Dear Ansible enthousiasts,
When I write a role, I’d like to tell what are the variables that tasks and templates will use. To prevent the interruption of the playbook in the middle of the execution of a role because a variable is not set, I also want to ensure that the playbook defines all mandatory variables.
My current approach is to provide a file tasks/init.yml
in the role with an assert command such as:
- assert:
that:
- var != ''
tags: ["check"]
Then I include the file in tasks/main.yml
:
- include: init.yml
- ...
I can check the role with ansible-playbook -i inventory playbook.yml -t check
.
What do you think about that? Do you have best practices to solve the same problems?
Your feedback is welcome :).
Cheers,
- Greg