Ansible - Create null variables
by
Jeremy Canfield |
Updated: September 20 2022
| Ansible articles
Let's say you are using the vars plugin to create variables. Notice in this example that var2 contains null and var3 contains no value.
---
- hosts: localhost
vars:
var1: "Hello World"
var2: null
var3:
...
Or like this, using set_fact.
---
- hosts: localhost
tasks:
- set_fact:
var1: "Hello World"
- set_fact:
var2: null
- set_fact:
var3:
...
The debug module can be used to print the value of each variable.
---
- hosts: localhost
tasks:
- set_fact:
var1: "Hello World"
- set_fact:
var2: null
- set_fact:
var3:
- debug:
var: var1
- debug:
var: var2
- debug:
var: var3
...
Something like this should be returned. Notice that both var2 and var3 contain no value.
ok: [localhost] => {
"var1": "Hello World"
}
ok: [localhost] => {
"var2": ""
}
ok: [localhost] => {
"var3": ""
}
Did you find this article helpful?
If so, consider buying me a coffee over at