# Problem with groups in inventory

**URL:** <https://forum.ansible.com/t/problem-with-groups-in-inventory/26463>\
**Category:** Ansible Project\
**Tags:** rhel, ubuntu\
**Created:** [January 11, 2018, 5:59pm UTC](https://forum.ansible.com/t/problem-with-groups-in-inventory/26463 "2018-01-11T17:59:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Barlock](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@Chris\_Barlock](https://forum.ansible.com/u/Chris_Barlock)\
**Post date:** [January 11, 2018, 5:59pm UTC](https://forum.ansible.com/t/problem-with-groups-in-inventory/26463/1 "2018-01-11T17:59:27Z")

</div>

I posted this yesterday, but have yet to see it show up in the forum:

I have the following in one of my playbooks:

- name: “Copy SSH keys”

command: sshpass -f ~/temp.pass ssh-copy-id -i ~/.ssh/id\_rsa.pub {{ ansible\_user }}@{{ item }}

with\_flattened:

- groups.worker

- groups.proxy

when: item not in groups.master

with this inventory file:

[master]

9.42.23.241 kubelet\_extra\_args=‘[“–eviction-hard=memory.available\<100Mi,nodefs.available\<2Gi,nodefs.inodesFree\<5%”, “–image-gc-high-threshold=100%”, “–image-gc-low-threshold=100%”]’

[worker]

9.42.23.147

[proxy]

9.42.23.241 kubelet\_extra\_args=‘[“–eviction-hard=memory.available\<100Mi,nodefs.available\<2Gi,nodefs.inodesFree\<5%”, “–image-gc-high-threshold=100%”, “–image-gc-low-threshold=100%”]’

[management]

9.42.23.241 kubelet\_extra\_args=‘[“–eviction-hard=memory.available\<100Mi,nodefs.available\<2Gi,nodefs.inodesFree\<5%”, “–image-gc-high-threshold=100%”, “–image-gc-low-threshold=100%”]’

This works fine when I run on an Ubuntu 16.04 system, but when I run on RHEL 7.4, I get:

failed: [9.42.23.241] (item=groups.worker) =\> {“changed”: true, “cmd”: [“sshpass”, “-f”, “~/temp.pass”, “ssh-copy-id”, “-i”, “~/.ssh/id\_rsa.pub”, “root@groups.worker”], “delta”: “0:00:00.128010”, “end”: “2018-01-11 12:55:19.491284”, “failed”: true, “item”: “groups.worker”, “msg”: “non-zero return code”, “rc”: 1, “start”: “2018-01-11 12:55:19.363274”, “stderr”: “/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id\_rsa.pub"\n/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed\n\n/usr/bin/ssh-copy-id: ERROR: ssh: Could not resolve hostname groups.worker: Name or service not known”, “stderr\_lines”: [“/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id\_rsa.pub"”, “/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed”, “”, “/usr/bin/ssh-copy-id: ERROR: ssh: Could not resolve hostname groups.worker: Name or service not known”], “stdout”: “”, “stdout\_lines”: }

failed: [9.42.23.241] (item=groups.proxy) =\> {“changed”: true, “cmd”: [“sshpass”, “-f”, “~/temp.pass”, “ssh-copy-id”, “-i”, “~/.ssh/id\_rsa.pub”, “root@groups.proxy”], “delta”: “0:00:00.122724”, “end”: “2018-01-11 12:55:19.942384”, “failed”: true, “item”: “groups.proxy”, “msg”: “non-zero return code”, “rc”: 1, “start”: “2018-01-11 12:55:19.819660”, “stderr”: “/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id\_rsa.pub"\n/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed\n\n/usr/bin/ssh-copy-id: ERROR: ssh: Could not resolve hostname groups.proxy: Name or service not known”, “stderr\_lines”: [“/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id\_rsa.pub"”, “/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed”, “”, “/usr/bin/ssh-copy-id: ERROR: ssh: Could not resolve hostname groups.proxy: Name or service not known”], “stdout”: “”, “stdout\_lines”: }

to retry, use: --limit @/root/ansible/deploy.retry

As you can see, groups.workers and groups.proxy are taken as literal strings and are the IP addresses are not substituted. Should I be doing this another way?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 12, 2018, 3:32pm UTC](https://forum.ansible.com/t/problem-with-groups-in-inventory/26463/2 "2018-01-12T15:32:10Z")

</div>

> I have the following in one of my playbooks:
> 
> - name: "Copy SSH keys"  
> &nbsp;&nbsp;command: sshpass -f ~/temp.pass ssh-copy-id -i ~/.ssh/id\_rsa.pub {{ ansible\_user }}@{{ item }}  
> &nbsp;&nbsp;with\_flattened:  
> &nbsp;&nbsp;&nbsp;&nbsp;- groups.worker  
> &nbsp;&nbsp;&nbsp;&nbsp;- groups.proxy  
> &nbsp;&nbsp;when: item not in groups.master

\<snip /\>

> As you can see, groups.workers and groups.proxy are taken as literal  
> strings and are the IP addresses are not substituted. Should I be doing  
> this another way?

Yes, if you want to use variables you need to enclose them in {{ }}  
&nbsp;&nbsp;&nbsp;&nbsp;- '{{ groups.worker }}'  
&nbsp;&nbsp;&nbsp;&nbsp;- '{{ groups.proxy }}'

---

<div class="post-metadata">

**Author:** ![Chris\_Barlock](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@Chris\_Barlock](https://forum.ansible.com/u/Chris_Barlock)\
**Post date:** [January 12, 2018, 5:12pm UTC](https://forum.ansible.com/t/problem-with-groups-in-inventory/26463/3 "2018-01-12T17:12:54Z")

</div>

Thank you! That worked. Tricker syntax because you need the braces in the with\_flattened element, but not in the when element.

Chris

---

<div class="post-metadata">

**Author:** ![Chris\_Barlock](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@Chris\_Barlock](https://forum.ansible.com/u/Chris_Barlock)\
**Post date:** [January 12, 2018, 5:13pm UTC](https://forum.ansible.com/t/problem-with-groups-in-inventory/26463/4 "2018-01-12T17:13:31Z")

</div>

Tricky that is!

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 12, 2018, 6:10pm UTC](https://forum.ansible.com/t/problem-with-groups-in-inventory/26463/5 "2018-01-12T18:10:43Z")

</div>

It easy to remember, only place you can't use them is in when, every other places the brackets is mandatory.

---

<div class="post-metadata">

**Author:** ![Chris\_Barlock](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@Chris\_Barlock](https://forum.ansible.com/u/Chris_Barlock)\
**Post date:** [January 13, 2018, 12:42am UTC](https://forum.ansible.com/t/problem-with-groups-in-inventory/26463/6 "2018-01-13T00:42:38Z")

</div>

Thank you! Really odd, though, that it worked on Ubuntu without the braces, but failed on RedHat.

---

<div class="post-metadata">

**Author:** ![chaitanya\_p](https://avatars.discourse-cdn.com/v4/letter/c/46a35a/32.png) [@chaitanya\_p](https://forum.ansible.com/u/chaitanya_p)\
**Post date:** [January 13, 2018, 8:20am UTC](https://forum.ansible.com/t/problem-with-groups-in-inventory/26463/7 "2018-01-13T08:20:19Z")

</div>

🕶

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 13, 2018, 10:00am UTC](https://forum.ansible.com/t/problem-with-groups-in-inventory/26463/8 "2018-01-13T10:00:09Z")

</div>

You probably have an older version of Ansible on the Ubuntu machine since the older version do allow using variables without the brackets.

---

<div class="post-metadata">

**Author:** ![Chris\_Barlock](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@Chris\_Barlock](https://forum.ansible.com/u/Chris_Barlock)\
**Post date:** [January 15, 2018, 11:32pm UTC](https://forum.ansible.com/t/problem-with-groups-in-inventory/26463/9 "2018-01-15T23:32:09Z")

</div>

Makes sense, thanks!
