# Wait For Host with Variable Fails

**URL:** <https://forum.ansible.com/t/wait-for-host-with-variable-fails/25787>\
**Category:** Ansible Project\
**Created:** [October 20, 2017, 4:08am UTC](https://forum.ansible.com/t/wait-for-host-with-variable-fails/25787 "2017-10-20T04:08:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ken\_Jenney](https://avatars.discourse-cdn.com/v4/letter/k/c2a13f/32.png) [@Ken\_Jenney](https://forum.ansible.com/u/Ken_Jenney)\
**Post date:** [October 20, 2017, 4:08am UTC](https://forum.ansible.com/t/wait-for-host-with-variable-fails/25787/1 "2017-10-20T04:08:51Z")

</div>

I use a script to find an available IP on my network and then assign that IP to a system. The system is up and running with the new IP but wait\_for\_host fails. It looks like the newline is causing issues:

`

- name: Find a free IP  
local\_action: script files/find\_free\_ip.py {{ startip }} {{ endip }}  
register: freeip  
become: “no”

- name: Assign the correct IP and Hostname to the VM  
script: files/set\_ip\_and\_hostname.sh {{ initialip }} {{ freeip.stdout }} {{ hostname }}  
changed\_when: “False”  
delegate\_to: “{{ initialip }}”

- name: Wait for VM to become available  
local\_action: wait\_for host={{ freeip.stdout }} port=22 delay=1   
state=started timeout=300  
become: “no”

fatal: [nj-kvm02 → localhost]: FAILED! =\> {“changed”: false, “elapsed”: 300, “failed”: true, “msg”: “Timeout when waiting for 192.168.1.147\n:22”}  
`

How can I strip the newline character and just store the bare string in a variable for re-use?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [October 20, 2017, 5:46am UTC](https://forum.ansible.com/t/wait-for-host-with-variable-fails/25787/2 "2017-10-20T05:46:29Z")

</div>

According to  
[http://jinja.pocoo.org/docs/dev/templates/#list-of-builtin-filters](http://jinja.pocoo.org/docs/dev/templates/#list-of-builtin-filters)  
you have the trim filter.

{{ freeip.stdout | trim }}

Storing for reuse you could use set\_fact module.  
- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;vm\_ip: '{{ freeip.stdout | trim }}'

---

<div class="post-metadata">

**Author:** ![Ken\_Jenney](https://avatars.discourse-cdn.com/v4/letter/k/c2a13f/32.png) [@Ken\_Jenney](https://forum.ansible.com/u/Ken_Jenney)\
**Post date:** [October 20, 2017, 1:23pm UTC](https://forum.ansible.com/t/wait-for-host-with-variable-fails/25787/3 "2017-10-20T13:23:19Z")

</div>

Kai,

Thanks for the help! This works beautifully.
