Wait For Host with Variable Fails

14 views
Skip to first unread message

Ken Jenney

unread,
Oct 20, 2017, 12:08:51 AM10/20/17
to Ansible Project
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?

Kai Stian Olstad

unread,
Oct 20, 2017, 1:46:48 AM10/20/17
to ansible...@googlegroups.com
According to
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:
vm_ip: '{{ freeip.stdout | trim }}'

--
Kai Stian Olstad

Ken Jenney

unread,
Oct 20, 2017, 9:23:19 AM10/20/17
to Ansible Project
Kai,

Thanks for the help! This works beautifully.
Reply all
Reply to author
Forward
0 new messages