I was wondering if there was any way to update the address that Ansible uses to ssh into a host mid-playbook.
I’m trying to write a script that will shutdown an AWS EC2 host, start a snapshot of the root volume, boot it back up, and perform some other tasks. The catch is that the address of this instance changes when it reboots and Ansible keeps using the address it retrieved at the beginning of the playbook via the dynamic inventory script, causing the rest of the actions to fail.
I’ve considered breaking the playbook into two different files so I can refresh the hosts cache after the box starts back up, but I’d prefer to execute all the tasks in one run. I’ve also tried looking around for some fact I could set to change the address Ansible uses to ssh, but I haven’t found anything.
Is it possible to change the address Ansible is using to ssh from within the playbook? If it is, how can I change it?
Rather than post a new thread, I thought that I would resurrect this one, as Brian’s suggestion - to use meta: refresh_inventory sounds to be exactly what I’m looking for. However, after some number of attempts, I can not seem to get it to work. Does anyone have an example that they wouldn’t mind posting?
I put what I found in some comments on this stackoverflow article, but have you tried disabling the cache on the dynamic inventory? To disable, set cache_max_age = 0 in the ec2.ini file.
This was the issue for me, so maybe it’ll help you.
I’ve just checked the rax.py file that we’re using for our inventory, and I can’t find any reference to any caching. If you have a minute Liam, would you mind pasting a working example of how you’re using meta: refresh_inventory? It’ll most likely turn out to be something that I have done incorrectly.