I'm trying to use either lineinfile or blockinfile to make a change to a 
sudoers.ansible file then copy this back over the sudoers once its 
validated as correctly formatted. 

I can see that the changes go ahead and I can manually run visudo -q -c -f 
and get no error meaning the file is ok.

Ansible seems to be interpreting to no stderr as an rc:1 failed result and 
the playbook crashes out... .was told this isnt a bug and is a question so 
any assistance would be great.

Details below : 

ANSIBLE VERSION

ansible 2.2.0.0
  config file =
  configured module search path = Default w/o overrides

CONFIGURATIONOS / ENVIRONMENTSUMMARY

If you attempt to validate changes to a /etc/sudoers file - even if it is a 
sudoers.ansible, etc it will fail if you attempt to validate or run via 
command visudo -q -c -f /etc/sudoers.ansible with no stdout
STEPS TO REPRODUCE

 basic check command 


  - name: Final sudoers file check before copying tmp back
    become: yes
    command: 'visudo -q -cf /etc/sudoers.ansible'
    register: checkok

it also fails if you attempt to run as a validate from lineinfile or 
blockinfile like 

validate: 'visudo -q -c -f %s'


EXPECTED RESULTS

Expected to pass and register as 'ok'
ACTUAL RESULTS

TASK [Final sudoers file check before copying tmp back] ************************
task path: /Users/<snip>/provision_lab.yml:143
Using module file 
/Library/Python/2.7/site-packages/ansible/modules/core/commands/command.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: <snip>
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo 
$HOME/.ansible/tmp/ansible-tmp-1491238255.64-78253062874287 `" && echo 
ansible-tmp-1491238255.64-78253062874287="` echo 
$HOME/.ansible/tmp/ansible-tmp-1491238255.64-78253062874287 `" ) && sleep 0'
<127.0.0.1> PUT /var/folders/sj/zdn5tb0d51q_20z4gm0myg700000gn/T/tmpqDb6kH TO 
/Users/<snip>/.ansible/tmp/ansible-tmp-1491238255.64-78253062874287/command.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x 
/Users/<snip>/.ansible/tmp/ansible-tmp-1491238255.64-78253062874287/ 
/Users/<snip>/.ansible/tmp/ansible-tmp-1491238255.64-78253062874287/command.py 
&& sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'sudo -H -S  -p "[sudo via ansible, 
key=wtmauitocwoynsgcjeydluockganqqnp] password: " -u root /bin/sh -c '"'"'echo 
BECOME-SUCCESS-wtmauitocwoynsgcjeydluockganqqnp; /usr/bin/python 
/Users/<snip>/.ansible/tmp/ansible-tmp-1491238255.64-78253062874287/command.py; 
rm -rf "/Users/<snip>/.ansible/tmp/ansible-tmp-1491238255.64-78253062874287/" > 
/dev/null 2>&1'"'"' && sleep 0'
fatal: [localhost]: FAILED! => {
    "changed": true,
    "cmd": [
        "visudo",
        "-q",
        "-cf",
        "/etc/sudoers.ansible"
    ],
    "delta": "0:00:00.008161",
    "end": "2017-04-03 17:50:55.807571",
    "failed": true,
    "invocation": {
        "module_args": {
            "_raw_params": "visudo -q -cf /etc/sudoers.ansible",
            "_uses_shell": false,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "warn": true
        },
        "module_name": "command"
    },
    "rc": 1,
    "start": "2017-04-03 17:50:55.799410",
    "stderr": "",
    "stdout": "",
    "stdout_lines": [],
    "warnings": []
}

TASK [Final sudoers file check before copying tmp back] ************************
fatal: [localhost]: FAILED! => {"changed": true, "cmd": "visudo -q -c -f 
/etc/sudoers.ansible", "delta": "0:00:00.018836", "end": "2017-04-03 
17:12:29.915562", "failed": true, "rc": 1, "start": "2017-04-03 
17:12:29.896726", "stderr": "", "stdout": "", "stdout_lines": [], "warnings": 
[]}

-- 
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/3e38cb92-8744-49ee-86d1-53cdbe5ec9bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to