Find knowledge base article(s) by searching for keywords in the title e.g. type linux in the search box below
Find knowledge base article(s) by browsing the subject categories of articles
Technology quick references, cheatsheets, user manuals etc.
Shop Online through ShopifyLite
Tutorials on various IT applications.
Search Title    (UL:0 |SS:f)

Software >> Automation >> Ansible >> Modules >> debug >> Examples

 

debug


online help: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/debug_module.html
offline help: ansible-doc debug   (run this command on the ansible control node)

## PLAYBOOK

---
- name: ansible debug module - example 1
  hosts: all
  become: True
  tasks:

  - name: debug by printing messages or variables
    shell: uptime
    register: results
  - name: Debug by printing messages
    debug: msg="{{ results.stdout_lines }}"
  - name: Debug by printing variables
    debug: var=results.stdout_lines
  - name: get file stat to display info on multiple lines
    stat:
      path: /home/ansible/hello.txt
    register: fileinfo
  - debug:
      msg:
        - "line1: path={{fileinfo.stat.path}}"
        - "line2: mtime={{fileinfo.stat.mtime}}"
        - "line3: atime={{fileinfo.stat.atime}}"


## OUTPUT

PLAY [ansible debug module - example 1] PLAY [ansible debug module - example 1] ************************************************************

TASK [Gathering Facts] *****************************************************************************
ok: [ubuntu20_int]
ok: [debian11_int]

TASK [debug by printing messages or variables] *****************************************************
changed: [ubuntu20_int]
changed: [debian11_int]

TASK [Debug by printing messages] ******************************************************************
ok: [debian11_int] => {
    "msg": [
        " 12:12:53 up  3:04,  3 users,  load average: 0.21, 0.10, 0.03"
    ]
}
ok: [ubuntu20_int] => {
    "msg": [
        " 12:12:53 up  3:02,  3 users,  load average: 0.05, 0.03, 0.00"
    ]
}

TASK [Debug by printing variables] *****************************************************************
ok: [debian11_int] => {
    "results.stdout_lines": [
        " 12:12:53 up  3:04,  3 users,  load average: 0.21, 0.10, 0.03"
    ]
}
ok: [ubuntu20_int] => {
    "results.stdout_lines": [
        " 12:12:53 up  3:02,  3 users,  load average: 0.05, 0.03, 0.00"
    ]
}

TASK [get file stat to display info on multiple lines] *********************************************
ok: [ubuntu20_int]
ok: [debian11_int]

TASK [debug] ***************************************************************************************
ok: [debian11_int] => {
    "msg": [
        "line1: path=/home/ansible/hello.txt",
        "line2: mtime=1635299447.3124452",
        "line3: atime=1635299490.8528533"
    ]
}
ok: [ubuntu20_int] => {
    "msg": [
        "line1: path=/home/ansible/hello.txt",
        "line2: mtime=1635299449.8489878",
        "line3: atime=1635299492.513668"
    ]
}

PLAY RECAP *****************************************************************************************
debian11_int               : ok=6    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
ubuntu20_int               : ok=6    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

[ © 2008-2021 myfaqbase.com - A property of WPDC Consulting ]