# Ansible attributes unavailable when using a group filter

**URL:** <https://forum.ansible.com/t/ansible-attributes-unavailable-when-using-a-group-filter/23612>\
**Category:** Ansible Project\
**Created:** [February 1, 2017, 5:27pm UTC](https://forum.ansible.com/t/ansible-attributes-unavailable-when-using-a-group-filter/23612 "2017-02-01T17:27:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lee\_Connell](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@Lee\_Connell](https://forum.ansible.com/u/Lee_Connell)\
**Post date:** [February 1, 2017, 5:27pm UTC](https://forum.ansible.com/t/ansible-attributes-unavailable-when-using-a-group-filter/23612/1 "2017-02-01T17:27:27Z")

</div>

Hi all,

I am having an odd issue where if I use a group filter in my playbook, I can no longer access any of the `ansible_` facts. I am able to access the `ec2_` facts. If I remove my group filter, everything works fine.

### Playbook

---

<div class="post-metadata">

**Author:** ![Lee\_Connell](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@Lee\_Connell](https://forum.ansible.com/u/Lee_Connell)\
**Post date:** [February 2, 2017, 6:33pm UTC](https://forum.ansible.com/t/ansible-attributes-unavailable-when-using-a-group-filter/23612/2 "2017-02-02T18:33:24Z")

</div>

Anybody?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 2, 2017, 6:37pm UTC](https://forum.ansible.com/t/ansible-attributes-unavailable-when-using-a-group-filter/23612/3 "2017-02-02T18:37:16Z")

</div>

Doesn't it work as expected? you avoid gathering facts for machines in  
groups['db'] that are not also in 'prd'.

---

<div class="post-metadata">

**Author:** ![Lee\_Connell](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@Lee\_Connell](https://forum.ansible.com/u/Lee_Connell)\
**Post date:** [February 2, 2017, 11:47pm UTC](https://forum.ansible.com/t/ansible-attributes-unavailable-when-using-a-group-filter/23612/4 "2017-02-02T23:47:27Z")

</div>

Am I misunderstanding something? It works when using an ad-hoc command using the same parameters. Is this a hostvars issue? The groups exist with the correct hosts and thus as mentioned does contain the ec2\_ facts. If I execute the same via an ad-hoc command, you see the ansible\_ facts show up just fine.

cb\_ansible\_deploy $ ansible ‘db:&prd’ -m setup | grep ansible\_hostname  
“ansible\_hostname”: “cbdb-e1b-04”,  
“ansible\_hostname”: “cbdb-e1a-02”,  
“ansible\_hostname”: “cbdb-e1b-02”,  
“ansible\_hostname”: “cbdb-e1b-05”,  
“ansible\_hostname”: “cbdb-e1a-05”,  
“ansible\_hostname”: “cbdb-e1a-03”,  
“ansible\_hostname”: “cbdb-e1a-01”,  
“ansible\_hostname”: “cbdb-e1b-03”,  
“ansible\_hostname”: “cbdb-e1a-06”,  
“ansible\_hostname”: “cbdb-e1b-01”,  
“ansible\_hostname”: “cbdb-e1b-06”,  
“ansible\_hostname”: “cbdb-e1a-04”,

cb\_ansible\_deploy $ ansible-playbook wiki.yml -l ‘db:&prd’ --list-hosts

playbook: wiki.yml

play #1 (api:db:lb:d3:&prd): api:db:lb:d3:&prd TAGS: [facts]  
pattern: [u’api:db:lb:d3:&prd’]  
hosts (12):  
cbdb\_e1a\_01\_cb\_comcast\_net  
cbdb\_e1a\_06\_cb\_comcast\_net  
cbdb\_e1b\_05\_cb\_comcast\_net  
cbdb\_e1b\_03\_cb\_comcast\_net  
cbdb\_e1b\_06\_cb\_comcast\_net  
cbdb\_e1a\_05\_cb\_comcast\_net  
cbdb\_e1b\_02\_cb\_comcast\_net  
cbdb\_e1a\_04\_cb\_comcast\_net  
cbdb\_e1a\_02\_cb\_comcast\_net  
cbdb\_e1b\_01\_cb\_comcast\_net  
cbdb\_e1b\_04\_cb\_comcast\_net  
cbdb\_e1a\_03\_cb\_comcast\_net

play #2 (localhost): localhost TAGS: [local]  
pattern: [u’localhost’]  
hosts (0):

play #3 (adm): adm TAGS: [adm]  
pattern: [u’adm’]  
hosts (0):

cb\_ansible\_deploy $ ansible-playbook wiki.yml

PLAY [db:&prd] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [setup] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

ok: [cbdb\_e1a\_02]

ok: [cbdb\_e1a\_04]

ok: [cbdb\_e1a\_06]

ok: [cbdb\_e1a\_05]

ok: [cbdb\_e1b\_04]

ok: [cbdb\_e1b\_03]

ok: [cbdb\_e1b\_05]

ok: [cbdb\_e1b\_01]

ok: [cbdb\_e1a\_03]

ok: [cbdb\_e1a\_01]

ok: [cbdb\_e1b\_02]

ok: [cbdb\_e1b\_06]

PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [store date time] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

ok: [127.0.0.1]

TASK [build wiki] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

fatal: [127.0.0.1]: FAILED! =\> {“changed”: false, “failed”: true, “msg”: “AnsibleUndefinedVariable: ‘dict object’ has no attribute ‘ansible\_hostname’”}

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 2, 2017, 11:57pm UTC](https://forum.ansible.com/t/ansible-attributes-unavailable-when-using-a-group-filter/23612/5 "2017-02-02T23:57:46Z")

</div>

You are comparing a subset to a whole, 'db:&prd' != groups['db']  
unless all machines in 'db' that are in 'prd'.

---

<div class="post-metadata">

**Author:** ![Lee\_Connell](https://avatars.discourse-cdn.com/v4/letter/l/e99b99/32.png) [@Lee\_Connell](https://forum.ansible.com/u/Lee_Connell)\
**Post date:** [February 3, 2017, 1:17am UTC](https://forum.ansible.com/t/ansible-attributes-unavailable-when-using-a-group-filter/23612/6 "2017-02-03T01:17:33Z")

</div>

Ok, how do I accomplish what I am trying to do? I would like to be able to run my playbook on specific groups of hosts that are either in production or in staging depending on what is specified on the command line using limit. Right now I have all production and staging in say an api group. I then have a production and staging group that only have their corresponding hosts assigned.

[prd:children]  
tag\_Env\_Production

[stg:children]  
tag\_Env\_Staging

[api:children]  
tag\_Role\_API

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 3, 2017, 3:15pm UTC](https://forum.ansible.com/t/ansible-attributes-unavailable-when-using-a-group-filter/23612/7 "2017-02-03T15:15:46Z")

</div>

This will gather form api hosts always no matter how you limit the  
hosts, the drawback is that the loop is sequential.  
- hosts: localhost  
&nbsp;&nbsp;connection: local  
&nbsp;&nbsp;gather\_facts: no  
&nbsp;&nbsp;tags: [local]  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- name: gather api facts  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setup:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delegate\_to: "{{item}}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;delegate\_facts: True  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;with\_inventory\_hostname: api

&nbsp;&nbsp;&nbsp;&nbsp;- name: store date time  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set\_fact: date\_time="{{lookup('pipe','date')}}"  
&nbsp;&nbsp;&nbsp;&nbsp;- name: build wiki  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;template: src=roles/wiki/templates/wiki.test.j2  
dest=roles/wiki/files/wiki.html
