FreeKB - Ansible type_debug filter (integer, boolean, string, AnsibleUnicode, AnsibleUnsafeText, AnsibleVaultEncryptedUnicode)
Ansible - type_debug filter (integer, boolean, string, AnsibleUnicode, AnsibleUnsafeText, AnsibleVaultEncryptedUnicode)

type_debug is a filter that can be used to determine if the value stored in a variable is a boolean, an integer, AnsibleUnsafeText, AnsibleUnicode, or AnsibleVaultEncryptedUnicode.

  • AnsibleUnsafeText = a string, such as Hello World
  • AnsibleUnicode = a string, such as Hello World
  • AnsibleVaultEncryptedUnicode = a string encrypted by the ansible-vault command
  • boolean = true, false, yes, no, 1, 0
  • integer = a number other than 1 or 0, such as 123456

For example, lets say you create the following variables.

---
- hosts: localhost
  vars:
    var1: "Hello World"
    var2: true
    var3: 123
  tasks:
  - shell: ps
    register: out

  - set_fact:
      var4: out
...

 

The debug module can be used to determine the type of value in each variable.

- debug:
    msg: "The 'var1' variable contains a {{ var1 | type_debug }}"

- debug:
    msg: "The 'var2' variable contains a {{ var2 | type_debug }}"

- debug:
    msg: "The 'var3' variable contains a {{ var3 | type_debug }}"

- debug:
    msg: "The 'var4' variable contains a {{ var4 | type_debug }}"

 

Something like this should be returned.

TASK [debug]
ok: [server1.example.com] => {
    "msg": "The 'var1' variable contains a AnsibleUnicode"
}

TASK [debug]
ok: [server1.example.com] => {
    "msg": "The 'var2' variable contains a bool"
}

TASK [debug]
ok: [server1.example.com] => {
    "msg": "The 'var3' variable contains a int"
}

TASK [debug]
ok: [server1.example.com] => {
    "msg": "The 'var4' variable contains a AnsibleUnsafeText"
}

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter f0914 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |