Dubug in ansible

——————————-
[mohammedrafi@ansible ~]$ touch shaik
——————————-
[mohammedrafi@ansible ~]$ vim reg.yml

– hosts: localhost
tasks:
– command: stat shaik
register: one
– debug: var=one
——————————-
[mohammedrafi@ansible ~]$ ansible-playbook reg.yml
PLAY [localhost] ***************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [command] *****************************************************************
changed: [localhost]
TASK [debug] *******************************************************************
ok: [localhost] => {
one“: {
“changed”: true,
“cmd”: [
“stat”,
“shaik”
],
“delta”: “0:00:00.004461”,
“end”: “2017-03-10 18:14:22.470392”,
“rc”: 0,
“start”: “2017-03-10 18:14:22.465931”,
“stderr”: “”,
“stdout”: ” File: ‘shaik’\n Size: 0 \tBlocks: 0 IO Block: 4096 regular empty file\nDevice: 802h/2050d\tInode: 50367655 Links: 1\nAccess: (0664/-rw-rw-r–) Uid: ( 1000/mohammedrafi) Gid: ( 1000/mohammedrafi)\nContext: unconfined_u:object_r:user_home_t:s0\nAccess: 2017-03-10 18:12:06.762688451 +0000\nModify: 2017-03-10 18:12:06.762688451 +0000\nChange: 2017-03-10 18:12:06.762688451 +0000\n Birth: -“,
“stdout_lines”: [
” File: ‘shaik’”,
” Size: 0 \tBlocks: 0 IO Block: 4096 regular empty file”,
“Device: 802h/2050d\tInode: 50367655 Links: 1”,
“Access: (0664/-rw-rw-r–) Uid: ( 1000/mohammedrafi) Gid: ( 1000/mohammedrafi)”,
“Context: unconfined_u:object_r:user_home_t:s0”,
“Access: 2017-03-10 18:12:06.762688451 +0000”,
“Modify: 2017-03-10 18:12:06.762688451 +0000”,
“Change: 2017-03-10 18:12:06.762688451 +0000″,
” Birth: -”
],
“warnings”: []
}
}

PLAY RECAP *********************************************************************
localhost : ok=3 changed=1 unreachable=0 failed=0
——————————–
[mohammedrafi@ansible ~]$ vim reg.yml

– hosts: localhost
tasks:
– command: stat shaik
register: one
– debug: var=one.rc

[mohammedrafi@ansible ~]$ ansible-playbook reg.yml
PLAY [localhost] ***************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [command] *****************************************************************
changed: [localhost]
TASK [debug] *******************************************************************
ok: [localhost] => {
“one.rc”: “0”
}
PLAY RECAP *********************************************************************
localhost : ok=3 changed=1 unreachable=0 failed=0
—————————-
[mohammedrafi@ansible ~]$ vim reg.yml

– hosts: localhost
tasks:
– command: stat shaik
register: one
– debug: var=one.rc
when: one.rc == 1
————————–
[mohammedrafi@ansible ~]$ ansible-playbook reg.yml

PLAY [localhost] ***************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [command] *****************************************************************
changed: [localhost]
TASK [debug] *******************************************************************
skipping: [localhost]
PLAY RECAP *********************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0
————————————-

[mohammedrafi@ansible ~]$ vim reg.yml

– hosts: localhost
tasks:
– command: stat shaik
register: one
– debug: msg=”its a typo”
when: one.rc == 1
————————————
[mohammedrafi@ansible ~]$ ansible-playbook reg.yml
PLAY [localhost] ***************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [command] *****************************************************************
changed: [localhost]
TASK [debug] *******************************************************************
skipping: [localhost]
PLAY RECAP *********************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0
———————————–
[mohammedrafi@ansible ~]$ vim reg.yml

– hosts: localhost
tasks:
– command: stat shaik
register: one
– debug: msg=”its a typo”
when: one.rc == 0
[mohammedrafi@ansible ~]$ ansible-playbook reg.yml
PLAY [localhost] ***************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [command] *****************************************************************
changed: [localhost]
TASK [debug] *******************************************************************
ok: [localhost] => {
“msg”: “its a typo”
}
PLAY RECAP *********************************************************************
localhost : ok=3 changed=1 unreachable=0 failed=0

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s