|
[root@node1 ansible]# ansible testservers -m shell -a 'ls -l /nono'
192.168.100.131 | success | rc=0 >>
total 0
192.168.100.132 | FAILED | rc=2 >>
ls: cannot access /nono: No such file or directory
[root@node1 ansible]# cat re.yml
- hosts: testservers
remote_user: root
tasks:
- name: ls /nono
shell: /bin/ls /nono
register: result
ignore_errors: True
- name: test result
copy: content="ok" dest=/tmp/test
when: result.rc == 0
- name: test no result
copy: content="no ok" dest=/tmp/test
when: result.rc != 0
[root@node1 ansible]# ansible-playbook re.yml
PLAY [testservers] ************************************************************
GATHERING FACTS ***************************************************************
ok: [192.168.100.131]
ok: [192.168.100.132]
TASK: [ls /nono] **************************************************************
changed: [192.168.100.131]
failed: [192.168.100.132] => {"changed": true, "cmd": "/bin/ls /nono", "delta": "0:00:00.004437", "end": "2016-03-02 12:56:55.409736", "rc": 2, "start": "2016-03-02 12:56:55.405299", "warnings": []}
stderr: /bin/ls: cannot access /nono: No such file or directory
...ignoring
TASK: [test result] ***********************************************************
skipping: [192.168.100.132]
ok: [192.168.100.131]
TASK: [test no result] ********************************************************
skipping: [192.168.100.131]
ok: [192.168.100.132]
PLAY RECAP ********************************************************************
192.168.100.131 : ok=3 changed=1 unreachable=0 failed=0
192.168.100.132 : ok=3 changed=1 unreachable=0 failed=0
[root@node1 ansible]# ansible testservers -m shell -a 'ls -l /tmp/test'
192.168.100.131 | success | rc=0 >>
-rw-r--r-- 1 root root 2 Mar 2 12:55 /tmp/test
192.168.100.132 | success | rc=0 >>
-rw-r--r-- 1 root root 5 Mar 2 12:55 /tmp/test
[root@node1 ansible]# ansible testservers -m shell -a 'cat /tmp/test'
192.168.100.131 | success | rc=0 >>
ok
192.168.100.132 | success | rc=0 >>
no ok
[root@node1 ansible]# |
|
|