user1858059
user1858059

Reputation: 103

Splitting Ansible output into 2 different strings

I have the following on my playbook:

- name: Debug
  debug:
     msg: "{{ item.stdout }}"
  with_items:
     - "{{ tapip.results }}"
     - "{{ hostname.results }}"

Which returns me this:

TASK [Debug] *************************************************************************************************************************************************************************************************** ok: [localhost] => (item=None) => { "msg": "192.168.0.104" } ok: [localhost] => (item=None) => { "msg": "hostname1" }

I would like to break the hostname and ip into 2 different strings. What is the best way to achieve this?

btw, I have also tried the following:

- name: Debug
  debug:
     msg: "{{ item.stdout.0 }} {{ item.stdout.1 }}"
  with_items:
     - "{{ tapip.results }}"
     - "{{ hostname.results }}"

Which returns this:

TASK [Debug] *************************************************************************************************************************************************************************************************** ok: [localhost] => (item=None) => { "msg": "1" } ok: [localhost] => (item=None) => { "msg": "h" }

Any ideas would be appreciated

Upvotes: 0

Views: 271

Answers (2)

Mahesh Periyasamy
Mahesh Periyasamy

Reputation: 34

  • name: Debug debug: msg: "{{ item.stdout }}" with_items:
    • tapip.results
    • hostname.results

Upvotes: 0

Mahesh Periyasamy
Mahesh Periyasamy

Reputation: 34

Try this

  • name: Debug debug: msg: "{{ item.stdout }}" with_items:
    • tapip.results
    • hostname.results

Upvotes: 1

Related Questions