# Update Ansible SSH Address Mid-Playbook

**URL:** <https://forum.ansible.com/t/update-ansible-ssh-address-mid-playbook/19674>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [November 2, 2015, 11:27pm UTC](https://forum.ansible.com/t/update-ansible-ssh-address-mid-playbook/19674 "2015-11-02T23:27:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kincaid\_Savoie](https://avatars.discourse-cdn.com/v4/letter/k/8797f3/32.png) [@Kincaid\_Savoie](https://forum.ansible.com/u/Kincaid_Savoie)\
**Post date:** [November 2, 2015, 11:27pm UTC](https://forum.ansible.com/t/update-ansible-ssh-address-mid-playbook/19674/1 "2015-11-02T23:27:31Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [November 2, 2015, 11:56pm UTC](https://forum.ansible.com/t/update-ansible-ssh-address-mid-playbook/19674/2 "2015-11-02T23:56:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kincaid\_Savoie](https://avatars.discourse-cdn.com/v4/letter/k/8797f3/32.png) [@Kincaid\_Savoie](https://forum.ansible.com/u/Kincaid_Savoie)\
**Post date:** [November 3, 2015, 6:13pm UTC](https://forum.ansible.com/t/update-ansible-ssh-address-mid-playbook/19674/3 "2015-11-03T18:13:51Z")

</div>

We’re using 1.9.4, so I had to use set\_fact, but it worked like a charm! Thanks!

---

<div class="post-metadata">

**Author:** ![Dan\_Rough](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@Dan\_Rough](https://forum.ansible.com/u/Dan_Rough)\
**Post date:** [February 6, 2016, 8:54pm UTC](https://forum.ansible.com/t/update-ansible-ssh-address-mid-playbook/19674/4 "2016-02-06T20:54:02Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Liam\_Jones](https://avatars.discourse-cdn.com/v4/letter/l/77aa72/32.png) [@Liam\_Jones](https://forum.ansible.com/u/Liam_Jones)\
**Post date:** [February 26, 2016, 7:55am UTC](https://forum.ansible.com/t/update-ansible-ssh-address-mid-playbook/19674/5 "2016-02-26T07:55:02Z")

</div>

Hey Dan,

I put what I found in some comments on this [stackoverflow](http://stackoverflow.com/questions/29003420/reload-ansibles-dynamic-inventory) 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

---

<div class="post-metadata">

**Author:** ![Dan\_Rough](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@Dan\_Rough](https://forum.ansible.com/u/Dan_Rough)\
**Post date:** [February 26, 2016, 3:09pm UTC](https://forum.ansible.com/t/update-ansible-ssh-address-mid-playbook/19674/6 "2016-02-26T15:09:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dan\_Rough](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@Dan\_Rough](https://forum.ansible.com/u/Dan_Rough)\
**Post date:** [February 26, 2016, 4:04pm UTC](https://forum.ansible.com/t/update-ansible-ssh-address-mid-playbook/19674/7 "2016-02-26T16:04:07Z")

</div>

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.
