Thursday, August 13, 2015

Ensure boolean literals in ansible j2 template

variables:

---
var_true: "true"
var_0: 0
var_false: False
var_no: no
playbook:
- hosts: all
  tasks:
    - name: test
      debug: msg="var_true={{ var_true |bool|lower}} var_false={{ var_false | bool|lower }} var_0={{ var_0 |bool|lower}} var_yes={{ var_yes | bool|lower}}"
output:
"msg": "var_true=true var_false=false var_0=false var_yes=true" 
| bool  to ensure ‘True’ or ‘False’
| lower to ensure lowercase boolean literals for e.g. configs in Java world

No comments:

Post a Comment