Skip to content

Check a playbook is passing correct arguments when including a role by using the role argument spec? #3669

Answered by chriscroome
Rylon asked this question in Ideas
Discussion options

You must be logged in to vote

if my role was called "testrole" this would be automatically available as testrolehostvars?

No, you have to define it, for example add this to vars/main.yml:

testrolevarnames: "{{ q('varnames', '^testrole_') | sort }}"
testrolehostvars: "{{ dict(testrolevarnames | list | zip(q('vars', *testrolevarnames))) }}"

And then use this task to validate all variables starting with testrole_:

- name: Check test_ variables using meta/argument_specs.yml
  ansible.builtin.validate_argument_spec:
    argument_spec: "{{ (lookup('ansible.builtin.file', 'meta/argument_specs.yml') | from_yaml)['argument_specs']['main']['options'] }}"
    provided_arguments: "{{ testrolehostvars }}"

I'd expect Ansible to …

Replies: 5 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@Rylon
Comment options

@chriscroome
Comment options

@Rylon
Comment options

@chriscroome
Comment options

@Rylon
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Rylon
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants