Update Ansible SSH Address Mid-Playbook

227 views
Skip to first unread message

Kincaid Savoie

unread,
Nov 2, 2015, 6:44:49 PM11/2/15
to Ansible Project
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?

Thanks for any and all help!

Brian Coca

unread,
Nov 2, 2015, 6:56:19 PM11/2/15
to Ansible Project
So in 2.0 you can force ansible to re-execute the inventory script
with `meta: refresh_inventory`, but if you are using cache or older
versions try:

set_fact: ansible_ssh_host=127.0.0.1



--
Brian Coca

Kincaid Savoie

unread,
Nov 3, 2015, 1:13:51 PM11/3/15
to Ansible Project
We're using 1.9.4, so I had to use set_fact, but it worked like a charm! Thanks!

Dan Rough

unread,
Feb 6, 2016, 3:54:02 PM2/6/16
to Ansible Project
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?

Liam Jones

unread,
Feb 26, 2016, 9:52:51 AM2/26/16
to Ansible Project
Hey Dan,

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.

Cheers,
Liam

Dan Rough

unread,
Feb 26, 2016, 10:10:31 AM2/26/16
to ansible...@googlegroups.com
Hi Liam,

Thanks for responding - I'd all but given up on getting this to work.

I'm using Rackspace rather than AWS, I'll see if the Rackspace equivalent, rax.py has a similar issue with the cache.

Thanks again!

Dan.

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/Pi6cXCqG0Fw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/23f453bf-ced0-4446-ab56-da35d1c80250%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Dan Rough, Chief Operating Officer
t: +44 20 7253 2380 | m: +44 79 8073 9436 | linkedin | @danrough
Gamevy Limited, 3rd Floor, 87-88 Turnmill Street, London, EC1M 5QU

Dan Rough

unread,
Feb 26, 2016, 11:04:51 AM2/26/16
to ansible...@googlegroups.com
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.

Thanks! Dan.
Reply all
Reply to author
Forward
0 new messages