Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Retrieve build IP address during build for use by provisioner #290

Open
lbonilla68 opened this issue Nov 20, 2019 · 1 comment
Open

Retrieve build IP address during build for use by provisioner #290

lbonilla68 opened this issue Nov 20, 2019 · 1 comment

Comments

@lbonilla68
Copy link

Is there a way to programatically retrieve the IP address that was assigned by DHCP to the build so that I can pass it to a provisioner?

@lbonilla68
Copy link
Author

FYI the only way I was able to do this was by enabling logging in Packer and grep that file so I can pass the IP to Ansible.

"provisioners": [ { "type": "shell-local", "inline": [ "export BUILD_IP=\"$(grep -m 1 -o '[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}' {{ userpacker_log_path }})\"", "sed -i '/\\[tag_Environment_packer_windows]/a '$BUILD_IP /tmp/inventory/hosts", "ansible-playbook --limit tag_Environment_packer_windows -i /tmp/inventory ansible_playbook.yml ] }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant