Octopus.Script exported 2019-12-02 by BlueWombat belongs to ’ Hosts File’ category.
This template will update the value of your HOSTS file to what you define in this step. It will skip all lines that start with ”#” (comments), and all other lines will be deleted. Then the values defined in this step will be added. You can define as many entry lines as you want.
Parameters
When steps based on the template are included in a project’s deployment process, the parameters below can be set.
Hosts Entries
uhf_Hosts = 127.0.0.1,hostname.xyz 127.0.0.1,hostname2.xyz
A comma delimited list of IP’s and Hostnames
Script body
Steps based on this template will execute the following PowerShell script.
$hostsPath = "$env:windir\system32\drivers\etc\hosts"
Write-Host "Opening HOSTS file:$hostsPath"
$hostEntries = $OctopusParameters["uhf_Hosts"]
Write-Verbose "hostEntries:$hostEntries"
$lines = (Get-Content $hostsPath)
for ($i = 0; $i -lt $lines.Length; $i++) {
$line = $lines[$i]
if ($line -match "^#" -or $line -match "^[\s\t]*$") {
continue
}
$line = ""
$lines[$i] = $line
}
foreach ($hostEntry in $hostEntries.Split("`n")) {
Write-Verbose $hostEntry
$parts = $hostEntry.Split(",")
$ip = $parts[0]
Write-Verbose $ip
$hostname = $parts[1]
Write-Verbose $hostname
$line = "$ip`t`t`t$hostname"
Write-Host "Adding entry:$line"
$lines += $line
}
Out-File -FilePath $hostsPath -Encoding ascii -InputObject $lines.Where({ $_ -ne ""}) -Force
Provided under the Apache License version 2.0.
To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.
{
"Id": "79d6ce26-71bc-44c8-9228-d90cc7de9991",
"Name": "Update Hosts File",
"Description": "This template will update the value of your HOSTS file to what you define in this step.\nIt will skip all lines that start with \"#\" (comments), and all other lines will be deleted.\nThen the values defined in this step will be added. You can define as many entry lines as you want.",
"Version": 9,
"ExportedAt": "2019-12-02T05:53:03.714Z",
"ActionType": "Octopus.Script",
"Author": "BlueWombat",
"Packages": [],
"Parameters": [
{
"Id": "a815bb21-5ca4-4645-9076-e0e9c9042006",
"Name": "uhf_Hosts",
"Label": "Hosts Entries",
"HelpText": "A comma delimited list of IP's and Hostnames",
"DefaultValue": "127.0.0.1,hostname.xyz\n127.0.0.1,hostname2.xyz",
"DisplaySettings": {
"Octopus.ControlType": "MultiLineText"
}
}
],
"Properties": {
"Octopus.Action.Script.ScriptSource": "Inline",
"Octopus.Action.Script.Syntax": "PowerShell",
"Octopus.Action.Script.ScriptBody": "$hostsPath = \"$env:windir\\system32\\drivers\\etc\\hosts\"\nWrite-Host \"Opening HOSTS file:$hostsPath\"\n\n$hostEntries = $OctopusParameters[\"uhf_Hosts\"]\nWrite-Verbose \"hostEntries:$hostEntries\"\n\n$lines = (Get-Content $hostsPath)\n\nfor ($i = 0; $i -lt $lines.Length; $i++) {\n $line = $lines[$i]\n if ($line -match \"^#\" -or $line -match \"^[\\s\\t]*$\") {\n continue\n }\n\n $line = \"\"\n\n $lines[$i] = $line\n}\n\nforeach ($hostEntry in $hostEntries.Split(\"`n\")) {\n Write-Verbose $hostEntry\n $parts = $hostEntry.Split(\",\")\n $ip = $parts[0]\n Write-Verbose $ip\n $hostname = $parts[1]\n Write-Verbose $hostname\n $line = \"$ip`t`t`t$hostname\"\n Write-Host \"Adding entry:$line\"\n $lines += $line\n}\n\nOut-File -FilePath $hostsPath -Encoding ascii -InputObject $lines.Where({ $_ -ne \"\"}) -Force"
},
"Category": " Hosts File",
"HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/update-hosts-file.json",
"Website": "/step-templates/79d6ce26-71bc-44c8-9228-d90cc7de9991",
"Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAIAAAAiOjnJAAABfGlDQ1BJQ0MgUHJvZmlsZQAAKM+VkblLQ0EQhz+TSMSDKFpYiASJ2iTiAUEbiwQvUIsYwatJXi4hx+O9BAm2gq2gINp4FfoXaCtYC4KiCGJhZa1oo+E5LwkkCBbusjPf/nZn2JkFSzCppHRbP6TSWS0w4XMuLC457S/Y6KSFXoZCiq7OzI0H+XN83lNj+luPmYv/jYZIVFegpk54VFG1rPCk8PR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