Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add master host param #27

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions hiera.sh
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions hostfile.ps1
Original file line number Diff line number Diff line change
@@ -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;
}
32 changes: 31 additions & 1 deletion windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
}