Open rntbrgtt opened 4 years ago
Hi @rntbrgtt and thanks for the perfect bug report :tada:
I've reproduced the issue: setting the labels through the playbook file vars work, as does through extra-vars (-e ara_playbook_labels=foo,oof
) but setting them through the inventory like you mentioned doesn't work.
It doesn't work like this either:
localhost ansible_connection=local ara_playbook_labels=testing,inventory
We currently check for labels during the v2_playbook_on_play_start
callback hook where I would expect the variable to be available if it's defined in the inventory:
https://github.com/ansible-community/ara/blob/37499b64a081784438f94683f74e3d36e23e48d5/ara/plugins/callback/ara_default.py#L241-L244
Now I'm wondering if this is a regression or if it's never worked because there's a gap in the testing. Sorry about that. It'd be a good idea to do more tests with inventory files :+1:
I need to look into this further but in the meantime, maybe default_labels would work for your use case ?
Hi @dmsimard,
Thanks for taking your time to analyze the bug reported by me.
Using the variable inside ansible.cfg does not help me as I could not differentiate validation from production executions.
I already tried using the variable listed next to the host in the inventory file but it didn't work.
If we could filter the playbooks by Arguments I would not need to do it as "production"or "validation"is also listed there.
I really appreciate your help.
@rntbrgtt I found the problem.
When supplying ara_playbook_labels
through the playbook file vars or through extra-vars, they wind up in play_vars where we pick them up: https://github.com/ansible-community/ara/blob/37499b64a081784438f94683f74e3d36e23e48d5/ara/plugins/callback/ara_default.py#L235-L238
However, when provided by the inventory, they're in hostvars.
So, instead of:
play_vars["ara_playbook_labels"]
they're in
play_vars["hostvars"]["localhost"]["ara_playbook_labels"]
instead.
This is a bit problematic because instead of needing to check if there's something in play_vars (not free but relatively fast) we'd now need to iterate through each host in hostvars (localhost was just an example above). This might not scale very well when increasing the number of hosts but I think it's doable.
I don't know what to do about this one yet but thanks for highlighting the issue. ara doesn't do anything with hostvars right now, maybe it could also pick them up ?
What component is this about ?
I am not able to create a variable "ara_playbook_labels" on my inventory files. It works in the playbook file but not on the inventory.
head -2 inventories/production/hosts
[all:vars] ara_playbook_labels = 'production'
What is your ARA installation like ?
Ara 1.4 Installed from pip Virtual Env Debian GNU/Linux 10 (buster) Mysql Database
What is happening ?
The variable doesn't exist.
What should be happening ?
The variable should exist.