Why playbook take wrong values for group variables?

47 views
Skip to first unread message

Олег Боровых

unread,
Apr 29, 2018, 4:39:59 AM4/29/18
to Ansible Project
Hi,

I have a problem with groups variables.

Example: I have two inventory groups group_A and group_B, and also have the same name files in group_vars:

inventories/ 
           hosts.inv    
             [group_A]
               server1
               server2
             [group_B]
               server3
               server4
             group_vars/
                  group_A - file
                    var_port: 9001
                  group_B - file
                    var_port: 9002 

The problem is when i execute playbook :

 ansible-playbook  playbooks/playbook.yml -i inventories/hosts.inv -l group_B

playbook was executed for proper scope of servers (server3, server4) but it takes variables from group variables file group_A.

    expected result:        var_port: 9002
    in realty :             var_port: 9001

ansible 2.4.2.0

 I can't understand what I am doing wrong?

BR Oleg

Tony Chia

unread,
May 1, 2018, 4:35:41 PM5/1/18
to Ansible Project
Do you have the following files defined?
<playbook-dir>/group_vars/group_A.yml
<playbook-dir>/group_vars/group_B.yml
<playbook-dir>/group_vars/all.yml
<playbook-dir>/inventories/group_vars/all.yml

also, maybe try using "hosts: group_B" in playbooks/playbook.yml instead of "hosts:all"

Олег Боровых

unread,
May 4, 2018, 8:02:38 AM5/4/18
to Ansible Project
hi Tony,
   i have no files at all:  
 <playbook-dir>/group_vars/all.yml
 <playbook-dir>/inventories/group_vars/all.yml
  and i try to put   "hosts: group_B",  but it not resole this issue.  Playbook  apply changes to the servers from right group but, variables  it take from neighborhood group_vars/file.  

I have included ANSIBLE_DEBUG , and what i have found:

2018-05-03 15:23:23,663 p=129458 u=user | 129458 1525353803.66336: Loading data from /ansible/inventories/prod/group_vars/group_B.yml 

2018-05-03 15:23:23,663 p=129458 u=user | 129661 1525353803.66060: in run() - task 00505680-eccc-d94e-2b1b-0000000000f4 

2018-05-03 15:23:23,664 p=129458 u=user | 129661 1525353803.66458: calling self._execute()

2018-05-03 15:23:23,665 p=129458 u=user | 129458 1525353803.66589: Loading data from /ansible/inventories/prod/group_vars/group_A.yml

it is look like on playbook execution ansible scan all files with  variables in folder group_vars which have variable "var_port", last will win.....




вторник, 1 мая 2018 г., 22:35:41 UTC+2 пользователь Tony Chia написал:

Brian Coca

unread,
May 4, 2018, 9:43:27 AM5/4/18
to Ansible Project
The `hosts:` keyword is only used to select which hosts get targeted,
it has no influence on group membership, any host is ALWAYS a member
of ALL the groups as defined in inventory, so the variables for a host
always reflect ALL GROUPS.





--
----------
Brian Coca

Marcos Alano

unread,
May 4, 2018, 11:04:06 AM5/4/18
to ansible...@googlegroups.com
Interesting. Could you show us what yours "hosts:" line on playbook.yml?
> --
> You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CACVha7d8CM6kwVi0ESJdQMNb%3DgkdzQh0eGSg-FcA5p%3DNPOH3_A%40mail.gmail.com
.
> For more options, visit https://groups.google.com/d/optout.



--
Marcos H. Alano
Linux System Administrator
marcos...@gmail.com

Олег Боровых

unread,
May 6, 2018, 4:30:51 PM5/6/18
to Ansible Project
Hi Markos,
 my playbook looks like:

- hosts: group_B
roles:
- dse_agent_full_install


пятница, 4 мая 2018 г., 17:04:06 UTC+2 пользователь Marcos Alano написал:
Reply all
Reply to author
Forward
0 new messages