packer-plugin-ansible
packer-plugin-ansible copied to clipboard
Add expect_disconnect
Description
Which provisioning using Ansible, I often need to reboot the VM but there is no such option as expect_disconnect
Potential configuration
provisioner "ansible-local" {
max_retries = 5
playbook_dir = "ansible"
playbook_file = "reboot-playbook.yml"
timeout = "10m0s"
clean_staging_directory = true
}
+1 to this, I am trying to set up a playbook that calls the builtin reboot module, but any time I use that it fails with ==>: dial tcp 172.16.161.128:22: connect: connection refused for example and never reconnects.
@gadelkareem Do you have a workaround?
@BytesGuy yes workaround here https://github.com/gadelkareem/ubuntu20-vagrantbox/blob/main/packer/vagrant/ubuntu.pkr.hcl#L97
provisioner "ansible-local" {
max_retries = 5
playbook_dir = "packer/vagrant/ansible"
# galaxy_file = "packer/vagrant/ansible/requirements.yml"
playbook_file = "packer/vagrant/ansible/vagrant-playbook.yml"
timeout = "10m0s"
inventory_groups = ["base"]
clean_staging_directory = true
}
provisioner "shell" {
expect_disconnect = true
inline = ["sudo reboot now"]
pause_before = "10s"
timeout = "10m0s"
}
@gadelkareem Ah ok so basically we will have to break out of the playbook and run the reboot via Packer directly. That's going to be a bit messy to do in the middle where I need to do it but it will have to do for now 😂
Hopefully some kind of expect disconnect feature can be added to the plugin soon!