Ansible `stdout_lines` bug when used with the file module
mliudev opened this issue · 5 comments
There's currently a bug in Ansible where stdout_lines
always appends a new line. This new line causes the file module to choke with "msg": "file () is absent, cannot continue"
.
I'm working around this by using the difference set filter, for example:
- name: "MEDIUM | V-38465 | PATCH | Library files must have mode 0755 or less permissive"
file:
state: file
mode: "go-w"
path: "{{ item }}"
when: library_perms_audit.stdout
with_items: "{{ library_perms_audit.stdout_lines | difference(['']) }}"
tags:
- cat2
- medium
- V-38465
- patch
- file_perms
The open Ansible issue is here: ansible/ansible#15099. This issue happens in quite a few places in cat2.yml.
I am also experiencing the same issue. It seems to be some strange behavior with how Ansible captures output from the script module. In light of this bug, I believe it would be preferable to use the shell module for these one-liner find commands.
Not only am I getting the empty newline, but also the output from sshd's lastlog message and from pam_lastlog.
TASK [RHEL6-STIG : MEDIUM | V-38465 | AUDIT | Library files must have mode 0755 or less permissive] ***
ok: [myrhelhost] => {"changed": false, "rc": 0, "stderr": "", "stdout": "\r\nLast login: Fri Dec 2 20:26:32 UTC 2016 on pts/4\r\nLast login: Fri Dec 2 20:26:33 UTC 2016 on pts/4\r\n", "stdout_lines": ["", "Last login: Fri Dec 2 20:26:32 UTC 2016 on pts/4", "Last login: Fri Dec 2 20:26:33 UTC 2016 on pts/4"]}
TASK [RHEL6-STIG : MEDIUM | V-38465 | PATCH | Library files must have mode 0755 or less permissive] ***
failed: [myrhelhost] (item=) => {"failed": true, "item": "", "msg": "file () is absent, cannot continue", "path": "", "state": "absent"}
failed: [myrhelhost] (item=Last login: Fri Dec 2 20:26:32 UTC 2016 on pts/4) => {"failed": true, "item": "Last login: Fri Dec 2 20:26:32 UTC 2016 on pts/4", "msg": "file (Last login: Fri Dec 2 20:26:32 UTC 2016 on pts/4) is absent, cannot continue", "path": "Last login: Fri Dec 2 20:26:32 UTC 2016 on pts/4", "state": "absent"}
failed: [myrhelhost] (item=Last login: Fri Dec 2 20:26:33 UTC 2016 on pts/4) => {"failed": true, "item": "Last login: Fri Dec 2 20:26:33 UTC 2016 on pts/4", "msg": "file (Last login: Fri Dec 2 20:26:33 UTC 2016 on pts/4) is absent, cannot continue", "path": "Last login: Fri Dec 2 20:26:33 UTC 2016 on pts/4", "state": "absent"}
Do we want to apply this work around until Ansible fixes their upstream?
@shaunbrady I think it would be worthwhile to convert these from using the script
module to just being one line command
or shell
tasks if that will fix the issue. I think the reason they were split out to be separate scripts was due to some old formatting issues with Ansible pre-2.0.
Game for that. I don't see much traction on the Ansible side, but to be fair, I haven't successfully chases down the location of the issue or if it's reproducible in new Ansibles (which we are not on yet....). I will see if I can come up with a PR.
Fixed by #108