How to use the task output as a listvar for another task

Hi guys,

Can you please help in these.
If I have a task inside of a playbook that give the following result:

[ansible@ansible ~]$ ansible node1 -m getent -a ‘database=group key=users split=“,”’
node1 | SUCCESS => {
“ansible_facts”: {
“getent_group”: {
“users:x:100:user1”: [
“user2”,
“user3”,
“user4”,
“user5”,
“user6”,
“user7”
]
}
},
“changed”: false
}

How can I register and use it, as a list var for another task?
For example:

  • user:
    name: “{{ item }}”
    comment: ‘N/{{item}}/contactForTheUser’
    with_items:

  • user2

  • user3

  • user4

  • user5

  • user6

  • user7

  • user:
    name: “{{ item }}”
    comment: ‘N/{{item}}/contactForTheFuckingUser’
    with_items:

{{ listvarFromOutput }}

By the way, thanks a lot for all support to all of us. :slight_smile:

MBrito

or use this output:

[ansible@ansible ~]$ ansible node1 -m getent -a ‘database=group key=users split=“users:x:100:”’
node1 | SUCCESS => {
“ansible_facts”: {
“getent_group”: {
“”: [
“user1,user2,ser3,user4,user5,
user6,user7”
]
}
},
“changed”: false
}

Hi guys,

Can you please help in these.
If I have a task inside of a playbook that give the following result:

[ansible@ansible ~]$ ansible node1 -m getent -a 'database=group key=users
split=","'
node1 | SUCCESS => {
    "ansible_facts": {
        "getent_group": {
            "users:x:100:user1": [
                "user2",
                "user3",
                "user4",
                "user5",
                "user6",
                "user7"
            ]
        }
    },
    "changed": false
}

You would need to put it in a play and lose the split part.

How can I register and use it, as a list var for another task?
For example:
   - user:
        name: "{{ item }}"
        comment: 'N/{{item}}/contactForTheUser'
      with_items:
        - user2
        - user3
        - user4
        - user5
        - user6
        - user7

   - user:
        name: "{{ item }}"
        comment: 'N/{{item}}/contactForTheFuckingUser'
      with_items:
         {{ listvarFromOutput }}

Then you can use
   with_items: "{{ getent_group.users.2.split(',') }}"