# using either command or validate on visudo with no stdout is always a fatal result.....

**URL:** <https://forum.ansible.com/t/using-either-command-or-validate-on-visudo-with-no-stdout-is-always-a-fatal-result/24131>\
**Category:** Ansible Project\
**Created:** [April 3, 2017, 7:28pm UTC](https://forum.ansible.com/t/using-either-command-or-validate-on-visudo-with-no-stdout-is-always-a-fatal-result/24131 "2017-04-03T19:28:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_McDonough](https://avatars.discourse-cdn.com/v4/letter/p/e56c9b/32.png) [@Paul\_McDonough](https://forum.ansible.com/u/Paul_McDonough)\
**Post date:** [April 3, 2017, 7:28pm UTC](https://forum.ansible.com/t/using-either-command-or-validate-on-visudo-with-no-stdout-is-always-a-fatal-result/24131/1 "2017-04-03T19:28:06Z")

</div>

##### 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.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [April 3, 2017, 8:00pm UTC](https://forum.ansible.com/t/using-either-command-or-validate-on-visudo-with-no-stdout-is-always-a-fatal-result/24131/2 "2017-04-03T20:00:11Z")

</div>

Try giving the full path to visudo.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [April 3, 2017, 8:06pm UTC](https://forum.ansible.com/t/using-either-command-or-validate-on-visudo-with-no-stdout-is-always-a-fatal-result/24131/3 "2017-04-03T20:06:42Z")

</div>

> 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.

Since you are using -q no output will be printed, even if there is an error in the file.  
You need to check(echo $?) the return code, if it's 1 then the file contains one or more errors.

> 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.

visudo is returning error code 1 because there is error(s) in the file, that's why Ansible fails.

> 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! =\> {  
> &nbsp;&nbsp;&nbsp;&nbsp;"changed": true,  
> &nbsp;&nbsp;&nbsp;&nbsp;"cmd": [  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"visudo",  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"-q",  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"-cf",  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"/etc/sudoers.ansible"  
> &nbsp;&nbsp;&nbsp;&nbsp;],  
> &nbsp;&nbsp;&nbsp;&nbsp;"delta": "0:00:00.008161",  
> &nbsp;&nbsp;&nbsp;&nbsp;"end": "2017-04-03 17:50:55.807571",  
> &nbsp;&nbsp;&nbsp;&nbsp;"failed": true,  
> &nbsp;&nbsp;&nbsp;&nbsp;"invocation": {  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"module\_args": {  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"\_raw\_params": "visudo -q -cf /etc/sudoers.ansible",  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"\_uses\_shell": false,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"chdir": null,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"creates": null,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"executable": null,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"removes": null,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"warn": true  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"module\_name": "command"  
> &nbsp;&nbsp;&nbsp;&nbsp;},  
> &nbsp;&nbsp;&nbsp;&nbsp;"rc": 1,

There are one or more errors in the file so visudo reports return code 1.  
In Ansible return code \>0 is default an error and the task fails.
