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 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 7f1bf18..0e5aecf 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) { @@ -65,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 +}