From 75f40a3eb6f33b6ac012d886cabc61fd20760b39 Mon Sep 17 00:00:00 2001 From: Marc Sutter Date: Wed, 11 Jun 2014 16:20:24 +0200 Subject: [PATCH 1/5] add master host param --- windows.ps1 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/windows.ps1 b/windows.ps1 index 7f1bf18..46a5577 100644 --- a/windows.ps1 +++ b/windows.ps1 @@ -19,10 +19,15 @@ .PARAMETER PuppetVersion This is the version of Puppet that you want to install. If you pass this it will override the version in the MsiUrl. This defaults to $null. + +.PARAMETER PuppetMaster + This is the hostname of the puppet master. + This defaults to $null. #> param( [string]$MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-3.3.2.msi" ,[string]$PuppetVersion = $null + ,[string]$PuppetMaster = $null ) if ($PuppetVersion -ne $null) { @@ -49,8 +54,14 @@ if (!($PuppetInstalled)) { Exit 1 } + if ($PuppetMaster -ne $null) { + $install_args = @("/qn", "/norestart","/i", $MsiUrl, "PUPPET_MASTER_SERVER $PuppetMaster") + } else { + $install_args = @("/qn", "/norestart","/i", $MsiUrl) + } + # Install it - msiexec will download from the url - $install_args = @("/qn", "/norestart","/i", $MsiUrl) + Write-Host "Installing Puppet. Running msiexec.exe $install_args" $process = Start-Process -FilePath msiexec.exe -ArgumentList $install_args -Wait -PassThru if ($process.ExitCode -ne 0) { From 89c60ac21b4ae5f684b764f967af56c19c5ce4ba Mon Sep 17 00:00:00 2001 From: Marc Sutter Date: Wed, 11 Jun 2014 16:25:08 +0200 Subject: [PATCH 2/5] fix MSI properties PUPPET_MASTER_SERVER --- windows.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows.ps1 b/windows.ps1 index 46a5577..f61c3e4 100644 --- a/windows.ps1 +++ b/windows.ps1 @@ -55,7 +55,7 @@ if (!($PuppetInstalled)) { } if ($PuppetMaster -ne $null) { - $install_args = @("/qn", "/norestart","/i", $MsiUrl, "PUPPET_MASTER_SERVER $PuppetMaster") + $install_args = @("/qn", "/norestart","/i", $MsiUrl, "PUPPET_MASTER_SERVER=$PuppetMaster") } else { $install_args = @("/qn", "/norestart","/i", $MsiUrl) } From bea85154857417ea2724925be7e0a19c8899a926 Mon Sep 17 00:00:00 2001 From: Marc Sutter Date: Wed, 11 Jun 2014 16:34:35 +0200 Subject: [PATCH 3/5] fix master host param --- windows.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows.ps1 b/windows.ps1 index f61c3e4..b1ab4d9 100644 --- a/windows.ps1 +++ b/windows.ps1 @@ -55,7 +55,7 @@ if (!($PuppetInstalled)) { } if ($PuppetMaster -ne $null) { - $install_args = @("/qn", "/norestart","/i", $MsiUrl, "PUPPET_MASTER_SERVER=$PuppetMaster") + $install_args = @("/qn", "/norestart","/i", "$MsiUrl", "PUPPET_MASTER_SERVER=$PuppetMaster") } else { $install_args = @("/qn", "/norestart","/i", $MsiUrl) } From 05c3b483ee924a010767a668e394945085d1db10 Mon Sep 17 00:00:00 2001 From: Marc Sutter Date: Wed, 11 Jun 2014 17:23:30 +0200 Subject: [PATCH 4/5] add hostfile --- hostfile.ps1 | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ windows.ps1 | 19 +++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 hostfile.ps1 diff --git a/hostfile.ps1 b/hostfile.ps1 new file mode 100644 index 0000000..ad55dbc --- /dev/null +++ b/hostfile.ps1 @@ -0,0 +1,59 @@ +<# + .DESCRIPTION + This function checks to see if an entry exists in the hosts file. + If it does not, it attempts to add it and verifies the entry. + + .EXAMPLE + hostfile -IPAddress 192.168.0.1 -HostName MyMachine + + .EXTERNALHELP + None. + + .FORWARDHELPTARGETNAME + None. + + .INPUTS + System.String. + + .LINK + None. + + .NOTES + None. + + .OUTPUTS + System.String. + + .PARAMETER IPAddress + A string representing an IP address. + + .PARAMETER HostName + A string representing a host name. + + .SYNOPSIS + Add entries to the hosts file. +#> + +param( + [parameter(Mandatory=$true,position=0)] +[string] +$IPAddress, +[parameter(Mandatory=$true,position=1)] +[string] +$HostName +) + +$HostsLocation = "$env:windir\System32\drivers\etc\hosts"; +$NewHostEntry = "`t$IPAddress`t$HostName"; + +if((gc $HostsLocation) -contains $NewHostEntry) +{ + Write-Host "The hosts file $HostsLocation already contains the following entry:"; + Write-Host "$NewHostEntry" +} +else +{ + Write-Host "Updating $HostsLocation file with:" + Write-Host "$NewHostEntry" + Add-Content -Path $HostsLocation -Value $NewHostEntry; +} \ No newline at end of file diff --git a/windows.ps1 b/windows.ps1 index b1ab4d9..0e5aecf 100644 --- a/windows.ps1 +++ b/windows.ps1 @@ -76,3 +76,22 @@ if (!($PuppetInstalled)) { Write-Host "Puppet successfully installed." } + +function add-hostfilecontent { + [CmdletBinding(SupportsShouldProcess=$true)] + param ( + [parameter(Mandatory=$true)] + [ValidatePattern("\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b")] + [string]$IPAddress, + + [parameter(Mandatory=$true)] + [string]$computer + ) + $file = Join-Path -Path $($env:windir) -ChildPath "system32\drivers\etc\hosts" + if (-not (Test-Path -Path $file)){ + Throw "Hosts file not found" + } + $data = Get-Content -Path $file + $data += "$IPAddress $computer" + Set-Content -Value $data -Path $file -Force -Encoding ASCII +} From b988699e8c946b61bda7c293c693255d5851373d Mon Sep 17 00:00:00 2001 From: Marc Sutter Date: Wed, 11 Jun 2014 18:51:03 +0200 Subject: [PATCH 5/5] add hiera --- hiera.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 hiera.sh diff --git a/hiera.sh b/hiera.sh new file mode 100644 index 0000000..32165da --- /dev/null +++ b/hiera.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# This adds hiera.yaml + +cat << EOF > /etc/puppet/hiera.yaml +:backends: + - yaml + +:hierarchy: + - 'nodes/%{::hostname}' + - 'roles/%{::role}' + - 'default' + +:yaml: +:datadir: '/etc/puppet/hieradata' + +:merge_behavior: deeper +EOF