Ansible role that checks that required variables are defined.
None.
Available variables are listed below, along with default values (see defaults/main.yml)
:
required_vars: {}
Set required variables to null e.g in defaults/main.yml
otherwise the role will fail if the variable is not defined with the following error:
"Unable to look up a name or access an attribute in template string ({{ required_vars | dict2items }}).\nMake sure your variable name does not contain invalid characters like '-': dict2items requires a dictionary, got <class 'ansible.template.native_helpers.AnsibleUndefined'> instead.. dict2items requires a dictionary, got <class 'ansible.template.native_helpers.AnsibleUndefined'> instead."
# defaults/main.yml
var1_name: null
var2_name: null
Pass the variable to check to required_vars
:
required_vars:
var1_name: "{{ var1_name }}"
var2_name: "{{ var2_name }}"
Add no_log
option for silent_vars
:
silent_vars:
- "var1_name"
None.
- name: Check required variables
hosts: all
become: true
roles:
- role: check-required-variables
required: "some value"
required_vars:
required: "{{ required }}"
- python >= 3.12
- docker
pip install -r requirements.txt
molecule test --all
MIT