Question:
I want to run ansible with user sa1 without sudo password:
First time OK:
1 2 3 4 |
[root@centos1 cp]# ansible cent2 -m shell -a "sudo yum -y install httpd" cent2 | SUCCESS | rc=0 >> |
Second time FAILED:
1 2 3 4 5 6 7 8 9 10 11 |
[root@centos1 cp]# ansible cent2 -s -m yum -a "name=httpd state=absent" cent2 | FAILED! => { "changed": false, "failed": true, "module_stderr": "", "module_stdout": "sudo: a password is required\r\n", "msg": "MODULE FAILURE", "parsed": false } |
Please help!
Answer:
It’s not ansible it’s your server’s configuration. Make sure that sudo is allowed for the user ansible is using without password.
- To do that login to the server
- Open the sudoers file with
sudo visudo
- Make sure you have a line something like this:
centos ALL=(ALL) NOPASSWD:ALL
- Replace
centos
with the your user - Save the file
You can try from the server itself by running:
1 2 |
sudo -u [yourusername] sudo echo "success" |
If this works it should work from ansible too.