Wait For Host with Variable Fails

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?

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,

Thanks for the help! This works beautifully.