Get stdout using loop

Hi! How i can get stdout using loop (f.e. for with_sequence statement)?

An example of how I want to use it:

Введите код...

  • hosts: 127.0.0.1
    connection: local
    gather_facts: no

    tasks:

    • name: “TEST”
      command: curl -o /dev/null --silent --head --write-out “%{http_code}” http://host"{{ item }}":80
      register: status
      with_sequence: count=4

    • debug: msg=“{{ item.stdout }}”

The above request was registered to a variable called “status”, but since you are using with_sequence this is saved in an array.

Take a look at what you have like so:

  • debug: var=status

Finally, you’ll probably see that you want:

  • debug: msg="{{ item.stdout }}
    with_items: status

item doesn’t mean anything unless there’s a loop in play, so you have to loop over status to use it.

status will be a list, so you have 4 stdout​s to look at:

  • debug: msg={{item.stdout}}
    with_items: status.results

In this case i got all message from status.results and stdout after it.

I solved this problem through this:

debug: msg="{% for results in status.results %} {{results.cmd.7}} - {{ results.stdout }} {% endfor %}"

In this case, I get what I need, but all 4 stdout output in a single line. How do I put a linebreak after each row (Ansible escapes ‘\n’).

Do what Brian said.

I’ve done it.

Playbook:

`