# How to use grouped/combined register variable output values \[values can be repeated/duplicate\] of multiple hosts?

**URL:** <https://forum.ansible.com/t/how-to-use-grouped-combined-register-variable-output-values-values-can-be-repeated-duplicate-of-multiple-hosts/26584>\
**Category:** Ansible Project\
**Created:** [January 29, 2018, 11:11am UTC](https://forum.ansible.com/t/how-to-use-grouped-combined-register-variable-output-values-values-can-be-repeated-duplicate-of-multiple-hosts/26584 "2018-01-29T11:11:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karthik\_V](https://avatars.discourse-cdn.com/v4/letter/k/8baadc/32.png) [@Karthik\_V](https://forum.ansible.com/u/Karthik_V)\
**Post date:** [January 29, 2018, 11:11am UTC](https://forum.ansible.com/t/how-to-use-grouped-combined-register-variable-output-values-values-can-be-repeated-duplicate-of-multiple-hosts/26584/1 "2018-01-29T11:11:33Z")

</div>

When I list the subnet cidr of every host in an environment I get repeated subent cidrs in the output as multiple hosts can be in same subnet.

What I’m trying to achieve is run a shell command in ansible for each unique subnet cidr from the above output.

Part of the playbook code for understanding purpose

```auto
   - name: Generate management cidr
     shell: echo {{ net_addr | ipaddr('net') }}
     register: management_cidr

   - debug:
     var: management_cidr.stdout

   - name: Apply iptables rule for Subnets[management_cidr]
     shell: iptables -A INPUT -p tcp -s {{ management_cidr.stdout }} -m comment --comment "Subnet Access" -m state --state NEW,ESTABLISHED -j ACCEPT

```

If I use the above playbook code it will apply duplicate iptables rules

**And the output of playbook**

```auto
TASK: [debug] 
****************************************************************
ok: [wephgyn01.wep.ani.ag.com] => {
    "var": {
        "management_cidr.stdout": "136.26.13.129/26"
    }
}
ok: [wephgyn02.wep.ani.ag.com] => {
    "var": {
        "management_cidr.stdout": "136.26.13.129/26"
    }
}
ok: [wephgyn03.wep.ani.ag.com] => {
    "var": {
        "management_cidr.stdout": "136.26.13.129/26"

```

. . . **[136.26.13.129/26 is repeated]**.

```auto
ok: [wepr05c001.wep.ani.ag.com] => {
    "var": {
        "management_cidr.stdout": "136.26.13.193/26"
    }
}
ok: [wepr04c018.wep.ani.ag.com] => {
    "var": {
        "management_cidr.stdout": "136.26.13.129/26"
    }
}
ok: [wepr05c002.wep.ani.ag.com] => {
    "var": {
        "management_cidr.stdout": "136.26.13.193/26"
    }
}

```

. . . **[136.26.13.193/26 is repeated]**.

```auto
ok: [wepr03c005.wep.ani.ag.com] => {
    "var": {
        "management_cidr.stdout": "136.26.13.65/26"
    }
}
ok: [wepr03c008.wep.ani.ag.com] => {
    "var": {
       "management_cidr.stdout": "136.26.13.65/26"
   }
}
ok: [wepr03c004.wep.ani.ag.com] => {
    "var": {
        "management_cidr.stdout": "136.26.13.65/26"
    }
}

```

**. . . [136.26.13.65/26 is repeated]**

So what I thought was to store register variable output into a list and make the list unique in Ansible and then use the list with the command.

Tried multiple sources but couldn’t find anything useful. Any ideas?
