Hello,
I encounter a bizarre behavior with these the shell module and the new
win_shell module.
It appears that, if the execution of the shell command does not produce
anything in the standard output, the module considers that it is in failure.
In my opinion, this should not be the case. Is this behavior an error or is
it voluntary?
I can use "ignore_errors: yes" to continue the playbook but it is not very
clean.
Here are some tasks to illustrate the problem :
# ----------------------------------
- name: "Use Case 1"
shell: grep "log" /etc/fstab
ignore_errors: yes
register: shell_result
- debug: var=shell_result
# ----------------------------------
- name: "Use Case 2"
shell: grep "xxx" /etc/fstab
ignore_errors: yes
register: shell_result
- debug: var=shell_result
# ----------------------------------
- name: "Use Case 3"
shell: grep "log" /etc/fstab >
/tmp/test_ansible/use_case_3_result.txt
ignore_errors: yes
register: shell_result
- debug: var=shell_result
# ----------------------------------
- name: "Use Case 4"
shell: grep "xxx" /etc/fstab >
/tmp/test_ansible/use_case_4_result.txt
ignore_errors: yes
register: shell_result
- debug: var=shell_result
Here are the results :
TASK [Use Case 1]
**************************************************************
changed: [lnildt01]
TASK [debug]
*******************************************************************
ok: [lnildt01] => {
"shell_result": {
"changed": true,
"cmd": "grep \"log\" /etc/fstab",
"delta": "0:00:00.003975",
"end": "2016-11-17 09:35:15.918729",
"rc": 0,
"start": "2016-11-17 09:35:15.914754",
"stderr": "",
"stdout": "/dev/mapper/rootvg-lv_logs /app/logs
\text4 defaults 1 2",
"stdout_lines": [
"/dev/mapper/rootvg-lv_logs /app/logs \text4
defaults 1 2"
],
"warnings": []
}
}
TASK [Use Case 2]
**************************************************************
fatal: [lnildt01]: FAILED! => {"changed": true, "cmd": "grep \"xxx\"
/etc/fstab", "delta": "0:00:00.003907", "end": "2016-11-17
09:35:16.234674", "failed": true, "rc": 1, "start": "2016-11-17
09:35:16.230767", "stderr": "", "stdout": "", "stdout_lines": [],
"warnings": []}
...ignoring
TASK [debug]
*******************************************************************
ok: [lnildt01] => {
"shell_result": {
"changed": true,
"cmd": "grep \"xxx\" /etc/fstab",
"delta": "0:00:00.003907",
"end": "2016-11-17 09:35:16.234674",
"failed": true,
"rc": 1,
"start": "2016-11-17 09:35:16.230767",
"stderr": "",
"stdout": "",
"stdout_lines": [],
"warnings": []
}
}
TASK [Use Case 3]
**************************************************************
changed: [lnildt01]
TASK [debug]
*******************************************************************
ok: [lnildt01] => {
"shell_result": {
"changed": true,
"cmd": "grep \"log\" /etc/fstab >
/tmp/test_ansible/use_case_3_result.txt",
"delta": "0:00:00.004247",
"end": "2016-11-17 09:35:16.547488",
"rc": 0,
"start": "2016-11-17 09:35:16.543241",
"stderr": "",
"stdout": "",
"stdout_lines": [],
"warnings": []
}
}
TASK [Use Case 4]
**************************************************************
fatal: [lnildt01]: FAILED! => {"changed": true, "cmd": "grep \"xxx\"
/etc/fstab > /tmp/test_ansible/use_case_4_result.txt", "delta":
"0:00:00.004442", "end": "2016-11-17 09:35:16.859715", "failed": true,
"rc": 1, "start": "2016-11-17 09:35:16.855273", "stderr": "", "stdout": "",
"stdout_lines": [], "warnings": []}
...ignoring
TASK [debug]
*******************************************************************
ok: [lnildt01] => {
"shell_result": {
"changed": true,
"cmd": "grep \"xxx\" /etc/fstab >
/tmp/test_ansible/use_case_4_result.txt",
"delta": "0:00:00.004442",
"end": "2016-11-17 09:35:16.859715",
"failed": true,
"rc": 1,
"start": "2016-11-17 09:35:16.855273",
"stderr": "",
"stdout": "",
"stdout_lines": [],
"warnings": []
}
}
The tasks "Use Case 2" and "Use Case 4" failed while the shell command was
executed correctly.
Moreover, in the use case 4, the file
/tmp/test_ansible/use_case_4_result.txt was created: the shell command has
therefore worked well.
NB1: This behavior is identical with the win_shell module for windows hosts.
NB2 : I can't downgrade the version of Ansible to test.
Regards,
Fabrice Perko
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/8f48d5f7-aa1f-4ddd-94c1-8f2eaad85ac4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.