# inventory host problem

**URL:** <https://forum.ansible.com/t/inventory-host-problem/34117>\
**Category:** Ansible Project\
**Created:** [October 27, 2020, 1:55pm UTC](https://forum.ansible.com/t/inventory-host-problem/34117 "2020-10-27T13:55:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnsibleJunior](https://avatars.discourse-cdn.com/v4/letter/a/e9c0ed/32.png) [@AnsibleJunior](https://forum.ansible.com/u/AnsibleJunior)\
**Post date:** [October 27, 2020, 1:55pm UTC](https://forum.ansible.com/t/inventory-host-problem/34117/1 "2020-10-27T13:55:31Z")

</div>

Hi everybody,  
I hope this the good place to post my problem.

I have declared this inventory in yml

all:  
children:  
server\_country\_prod:  
hosts:  
[server1.com](http://server1.com/):  
vars:  
…

server\_country\_preprod:  
hosts:  
[server2.com](http://server2.com/):  
vars:  
…

vars:

ansible\_ssh\_user: user  
ansible\_user: user  
ansible\_connection: ssh  
ssh\_args: -o ForwardAgent=yes

If I write that

- hosts: “{{ groups[‘server\_country\_prod’][0] }}”  
#gather\_facts: no  
become: yes  
I can lauch my playbook easily

But if I want lauching my playbook with extra var

ansible-playbook -i inventory.yml -e var1=server -e var2=country tasks/main.yml

I can’t lauch my playbook what I have writing

- hosts: " groups[‘{{var1}}\_{{var2}}\_prod’][0] "

I have the following error:  
PLAY [groups[‘server\_country\_prod’][0]] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
skipping: no hosts matched

Somebody can help me to understand why?  
Thanks for your read and your help.  
Best regards

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [October 27, 2020, 2:04pm UTC](https://forum.ansible.com/t/inventory-host-problem/34117/2 "2020-10-27T14:04:07Z")

</div>

> Hi everybody,  
> I hope this the good place to post my problem.
> 
> I have declared this inventory in yml  
> all:  
> children:  
> server\_country\_prod:  
> hosts:  
> server1.com \<[http://server1.com/&gt;:](http://server1.com/&gt;:)  
> vars:  
> ...
> 
> server\_country\_preprod:  
> hosts:  
> server2.com \<[http://server2.com/&gt;:](http://server2.com/&gt;:)  
> vars:  
> ....  
> vars:  
> ansible\_ssh\_user: user  
> ansible\_user: user  
> ansible\_connection: ssh  
> ssh\_args: -o ForwardAgent=yes
> 
> If I write that  
> - hosts: "{{ groups['server\_country\_prod'][0] }}"  
> #gather\_facts: no  
> become: yes  
> I can lauch my playbook easily
> 
> But if I want lauching my playbook with extra var  
> ansible-playbook -i inventory.yml -e var1=server -e var2=country tasks/main.yml
> 
> I can't lauch my playbook what I have writing  
> - hosts: " groups['{{var1}}\_{{var2}}\_prod'][0] "

groups is not inside {{ ... }}, so it isn't evaluated at all. Also you cannot  
nest the curly braces.

Try "{{ groups[var1 + '\_' var2 + '\_prod'][0] }}" (untested).

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![AnsibleJunior](https://avatars.discourse-cdn.com/v4/letter/a/e9c0ed/32.png) [@AnsibleJunior](https://forum.ansible.com/u/AnsibleJunior)\
**Post date:** [October 28, 2020, 9:47am UTC](https://forum.ansible.com/t/inventory-host-problem/34117/3 "2020-10-28T09:47:38Z")

</div>

“groups is not inside {{ … }}, so it isn’t evaluated at all. Also you cannot  
nest the curly braces.”  
Oh ok, I understand

I try this {{ groups[var1 + ‘\_’ var2 + ‘\_prod’][0] }}",

and it’s work perfectly, realy thank you for your help to an ansible newbie dev 🙂

Best regards
