-
Notifications
You must be signed in to change notification settings - Fork 46
/
playbook-pass-extra-vars.yml
37 lines (32 loc) · 1.07 KB
/
playbook-pass-extra-vars.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Example of overriding boolean variable using extra-vars
# Boolean MUST be passed as json
# because key/value pair gets interpreted as string that always evaluates to true
#
# blog: https://fabianlee.org/2021/07/28/ansible-overriding-boolean-values-using-extra-vars-at-runtime/
#
# will correctly say myflag is true, because that is the default
# ansible-playbook playbook-pass-extra-vars.yml
#
# will incorrectly say myflag is true
# ansible-playbook playbook-pass-extra-vars.yml --extra-vars "myflag=false"
#
# will correctly say myflag is false
# ansible-playbook playbook-pass-extra-vars.yml --extra-vars '{ "myflag": false }'
---
- hosts: localhost
connection: local
become: no
gather_facts: no
# false by default, override with json
vars:
myflag: true
tasks:
- debug:
msg: "myflag is true."
when: myflag
- debug:
msg: "myflag is false. You must have used a boolean sent as json or empty value"
when: not myflag
- debug:
msg: "myflag is false when using explicit boolean conversion"
when: not myflag|bool