Fw: "ansible_group_priority" option seems to be ignoring me

474 views
Skip to first unread message

Tomàs Núñez

unread,
Aug 28, 2018, 12:10:44 PM8/28/18
to Ansible Project
Hi
I'm trying to change the order in which our group_vars are loaded with ansible_group_priority but it's not working.

I have a role at roles/mytest/tasks/main.yaml like this:
_______________
- debug: var="myvar"
_______________

Then I have two group_vars files, one called inventory/group_vars/cluster_1.yaml with this values:
________________
ansible_group_priority: 10
myvar: cluster
________________

And another one called inventory/group_vars/role_1.yaml with this value:
________________
myvar: role
________________

Finally I have a playbook called mytest.yaml like this:
________________
- hosts: role_1&cluster_1
roles:
- mytest
________________

I think I'm reproducing exactly the example at https://docs.ansible.com/ansible/devel/user_guide/intro_inventory.html#how-variables-are-merged​ but the result is always "myvar: role". And of course, when I comment that line at role_1.yaml, the result is "myvar: cluster".

I've tried setting ansible_group_priority at role_1.yaml to 9 (and to 11, just in case), but it still happens the same. Well I think at this point I've tried all combinations :D

I'm using ansible version 2.4.0.0 but I also tried with 2.4.2.0 with the same results.

Can anyone spot anything that I'm doing wrong or did I just hit a bug?

Brian Coca

unread,
Aug 28, 2018, 1:53:34 PM8/28/18
to Ansible Project
You cannot set group priority in group_vars files as it handles the
priority in which group_vars files are read, you need to set it in the
main inventory source.

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

Tomàs Núñez

unread,
Aug 29, 2018, 6:25:23 AM8/29/18
to Ansible Project
I tried, but it's not working either. ​I just made a mini-version of our inventory script, adding the ansible_group_priority:
____________________
#!/bin/bash
cat << EOF
{
"cluster_1": {
"hosts": [
"host1"
],
"ansible_group_priority": 10
},
"role_1": {
"hosts": [
"host1",
"host2",
"host3",
],
"ansible_group_priority": 1
}
}
EOF​
_____________________

And when running my playbook I get:
_____________________
TASK [mytest : debug] *********************************************************
ok: [host1] => {
"myvar": "role"
}
_____________________

Just as a refresher, the contents of the playbook are:
_____________________
- hosts: role_1:&cluster_1
roles:
- { role: mytest, tags: mytest }
_____________________

Contents of inventory/group_vars/cluster_1.yaml:
________________
myvar: cluster
________________

And contents of inventory/group_vars/role_1.yaml:
________________
myvar: role
________________

I must be doing something wrong, because being ansible_group_priority higher for cluster, it should show "cluster", but it shows "role".

I tried setting the number 10between quotes and without them with the same result. Also tried removing priority from role (default value should be 1) with the same result.

Any ideas?

Tomàs Núñez

unread,
Aug 29, 2018, 6:53:25 AM8/29/18
to Ansible Project
I found the problem, I wasn't putting the priority inside "vars". The inventory that works is this one:
______________

#!/bin/bash
cat << EOF
{
"cluster_1": {
"hosts": [
"host1"
],
"vars": {

"ansible_group_priority": 10
}
},
"role_1": {
"hosts": [
"host1",
"host2",
"host3",
],
"vars": {
"ansible_group_priority": 1
}
}
}
EOF
______________

This returns "role" when running the playbook, as I was expecting.

Thanks a lot!!!

Reply all
Reply to author
Forward
0 new messages