https://github.com/artcom/ansible-role-check-required-variables
Ansible role that checks that required variables are defined
https://github.com/artcom/ansible-role-check-required-variables
Last synced: 7 months ago
JSON representation
Ansible role that checks that required variables are defined
- Host: GitHub
- URL: https://github.com/artcom/ansible-role-check-required-variables
- Owner: artcom
- License: mit
- Created: 2020-09-11T12:01:31.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2025-01-06T11:03:48.000Z (over 1 year ago)
- Last Synced: 2025-01-06T11:38:54.083Z (over 1 year ago)
- Language: Python
- Size: 8.79 KB
- Stars: 0
- Watchers: 15
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Check Required Variables
Ansible role that checks that required variables are defined.
## Requirements
None.
## Role Variables
Available variables are listed below, along with default values `(see defaults/main.yml)`:
```yaml
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:
```bash
"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 instead.. dict2items requires a dictionary, got instead."
```
```yaml
# defaults/main.yml
var1_name: null
var2_name: null
```
Pass the variable to check to `required_vars`:
```yaml
required_vars:
var1_name: "{{ var1_name }}"
var2_name: "{{ var2_name }}"
```
Add `no_log` option for `silent_vars`:
```yaml
silent_vars:
- "var1_name"
```
## Dependencies
None.
# Example Playbook
```yaml
- name: Check required variables
hosts: all
become: true
roles:
- role: check-required-variables
required: "some value"
required_vars:
required: "{{ required }}"
```
## Test
### Requirements
- python >= 3.12
- docker
### Run
```bash
pip install -r requirements.txt
molecule test --all
```
## License
MIT