Last active
October 9, 2022 10:34
-
-
Save adarobin/af1510c22c7d21395bb3284da04c0380 to your computer and use it in GitHub Desktop.
Using the Shell-Local provisioner for Ansible against Windows with Packer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "powershell", | |
"inline": [ | |
"switch -Wildcard ($env:PACKER_BUILDER_TYPE) {", | |
" \"amazon*\" { $publicipv4 = Invoke-RestMethod -Method GET -Uri http://169.254.169.254/latest/meta-data/public-ipv4 }", | |
" \"azure*\" { $publicipv4 = Invoke-RestMethod -Method GET -Uri \"http://169.254.169.254/metadata/instance/network/interface/0/ipv4/ipAddress/0/publicIpAddress?api-version=2017-12-01&format=text\" -Headers @{\"Metadata\" = \"true\"} }", | |
" \"googlecompute\" { $publicipv4 = Invoke-RestMethod -Method GET -Uri http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip -Headers @{\"Metadata-Flavor\" = \"Google\"} }", | |
" Default { Throw \"Unknown PACKER_BUILDER_TYPE\" } }", | |
"\"[{{build_name}}]\" | Out-File C:\\Windows\\Temp\\host -encoding ascii", | |
"$publicipv4 | Out-File C:\\Windows\\Temp\\host -encoding ascii" | |
] | |
}, | |
{ | |
"type": "file", | |
"direction": "download", | |
"source": "C:\\Windows\\Temp\\host", | |
"destination": "playbook/{{build_name}}-host" | |
}, | |
{ | |
"type": "shell-local", | |
"inline": [ | |
"export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES", | |
"case \"$PACKER_BUILDER_TYPE\" in", | |
" amazon*) ANSIBLE_USER={{user `aws_winrm_user`}};;", | |
" azure*) ANSIBLE_USER={{user `azure_winrm_user`}};;", | |
" googlecompute) ANSIBLE_USER={{user `gcp_winrm_user`}};;", | |
"esac", | |
"ansible-playbook -v -i playbook/{{build_name}}-host --extra-vars \"ansible_user=$ANSIBLE_USER ansible_password={{.WinRMPassword}} ansible_become_pass={{.WinRMPassword}} ansible_port=5986 ansible_connection=winrm ansible_winrm_server_cert_validation=ignore ansible_winrm_transport=ntlm\" playbook/main.yml" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment