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:
===============
host1:
     "stdout": "nfsflr01:/app01\n/app\n/etc/fstab",
     "stdout_lines": [
                "nfsflr01:/app01",
                "/app",
                "/etc/fstab"

host2:
    "stdout": "nfsflr02:/app02\n/app02\n/etc/fstab",
    "stdout_lines": [
        "nfsflr02:/app02",
        "/app02",
        "/etc/fstab"
host3:
     "stdout":
"nfsflr03:/app03\n/app03\n/etc/fstab\nnfsflr03:/app03\n/app03\n/etc/rc.willows",
     "stdout_lines": [
         "nfsflr03:/app03",
         "/app03",
         "/etc/fstab",
         "nfsflr03:/app03",
         "/app03",
         "/etc/rc.willows"

Regards,
Suresh



FAILED! => {"msg": "'dict object' has no attribute 'stdout'"}

On Sat, May 2, 2020 at 2:32 PM Kai Stian Olstad <
[email protected]> wrote:

> On Wed, Apr 29, 2020 at 03:44:14PM -0700, Suresh Karpurapu wrote:
> > 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
>
> 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 %}
>
> --
> Kai Stian Olstad
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/20200502090224.zygkso3iqpjok2bk%40olstad.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAHedzhKyABrV%2BS5N9w8vHF6fZtfb-WH7%2B7%3D41HuwieNqS41jVQ%40mail.gmail.com.

Reply via email to