Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ara_playbook_labels from inventory-vars #581

Open
NiceRath opened this issue Jan 20, 2025 · 2 comments
Open

feat: ara_playbook_labels from inventory-vars #581

NiceRath opened this issue Jan 20, 2025 · 2 comments

Comments

@NiceRath
Copy link

NiceRath commented Jan 20, 2025

What is the issue ?

It seems this might be feature-request as the current handling of ara_playbook_labels does not handle hostvars aka inventory-vars.

We try to pass some inventory-specific & group-specific labels to the ARA-client.

To ensure these are set as expected - we assert it inside our playbook:

- name: Test
  hosts: all
  become: true
  gather_facts: true
  pre_tasks:
    - ansible.builtin.assert:
        that:
          - ara_playbook_labels is defined
          - ara_playbook_labels | length > 0

But when I check-out the play_vars - the variable is not set?

...
raise ValueError("ara_playbook_labels" in play_vars, play_vars.keys())
if "ara_playbook_labels" in play_vars:
    ...

At: https://github.com/ansible-community/ara/blob/master/ara/plugins/callback/ara_default.py#L511

It Prints:

(False, dict_keys([<USER-SPECIFIC-VARS-REDACTED>, 'playbook_dir', 'ansible_playbook_python',
'ansible_config_file', 'ansible_role_names', 'ansible_play_role_names', 'ansible_dependent_role_names', 'role_names',
'ansible_play_name', 'groups', 'ansible_play_hosts_all', 'ansible_play_hosts', 'ansible_play_batch', 'play_hosts', 'omit',
'ansible_version', 'ansible_check_mode', 'ansible_diff_mode', 'ansible_forks', 'ansible_inventory_sources',
'ansible_skip_tags', 'ansible_limit', 'ansible_run_tags', 'ansible_verbosity', 'hostvars']))

When in the play_vars - the variable exists. But it seems to be nested under hostvars .

...
for k, v in play_vars.items():
    if v is not None and str(v).find("ara_playbook_labels") != -1:
        raise ValueError(k, v)
...

What should be happening ?

The documentation does only mention variables that are set in the playbook-context. But as Ansible allows also to set this variable in other ways - I would have expected it to work either way.

Two solutions come to my mind:

  • Either update the documentation, so it explicitly mentions that inventory-vars DO NOT work.
  • Or check the hostvars for ara_playbook_labels - I might supply a PR that enables this behaviour
@NiceRath NiceRath changed the title ara_playbook_labels not added ara_playbook_labels from inventory-vars not added Jan 20, 2025
@NiceRath NiceRath changed the title ara_playbook_labels from inventory-vars not added feat: ara_playbook_labels from inventory-vars Jan 20, 2025
@NiceRath
Copy link
Author

I understand that these labels are not host-specific, but specific to the execution.
But we should be able to iterate through the hostvars and extend the list of labels by all that we find..

@superstes
Copy link

PR: #582

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants