Need help on formating stdout_lines output

Hi All,

Would anyone please help me formatting mountchk.result. I am able to get the required output with item.stdout_lines[0],item.stdout_lines[1],item.stdout_lines[2] but host3 has 6 entries. So, please help me in filtering

mountchk.results:

Can anyone help me on this request?

Regards,
Suresh

You can use with_sequence or range in a for loop.

  vars:
    myvar:
      - one
      - two
      - three
      - four
      - five
      - six
  tasks:
    - debug: msg="{{ myvar[item | int] }},{{ myvar[item | int + 1] }},{{ myvar[item | int + 2] }}"
      with_sequence: start=0 end={{ (myvar | length) - 1 }} stride=3

    - debug:
        msg: |
          {% for i in range(0, myvar | length, 3) %}
          {{ myvar[i] }},{{ myvar[i + 1] }},{{ myvar[i + 2] }}
          {% endfor %}

Hi Sai Stian,

This syntax would be helpful but i may be using in wrong way as i am getting below errors. Please help on fixing the issue.

  • name: debug with with sequence
    debug:
    msg:“{{ volchk[item.stdout | int] }},{{ volchk[item.stdout | int + 1] }},{{ volchk[item.stdout | int + 2] }}”
    with_sequence: start=0 end={{ (volchk | length)-1 }} stride=3

error:

FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘ansible.utils.unsafe_proxy.AnsibleUnsafeBytes object’ has no attribute ‘stdout’\n\nThe error appears to be in ‘/suresh/suresh_playbooks/nfsvolmigration/roles/mountcheck/tasks/volcheck.yml’: line 44, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n ignore_errors: true\n - name: debug with with sequence\n ^ here\n”}

Debug “volchk.result” output:

Here is my playbook, i would like to display all lines in stdout_lines in below format without miss. I am able to display only first 3 lines but host03 has more than 3 lines even it may be more lines for other hosts. Would anyone please help me?

Required output fle:

would anyone please help me on this request?

Regards,
Suresh

Can you paste the content of “volchk” list … Also try using item.stdout_lines instead of item.stdout in your debug task.

thanks Neha, Kai

I could fix the issue by using range with stdout.split(). Even, it is working with stdout_lines as well

Once again thanks to all for helping me on this request.

Regards,
Suresh