In shell I am following the below approach to become root user without any password. And it is working fine.
ssh-agent bash
ssh-add /repository/ansible/.ssh/id_rsa_ansible
ssh -A ansible@e8-df1
[ansible@e8-df1 ~]$ sudo -i
[root@e8-df1 ~]#
However, In ansible, I do not achieve the same and getting error. Below is my ansible inventory and playbook.
Inventory:
[qv]
e8-df1
e8-df2
[qv:vars]
ansible_ssh_user=ansible
ansible_ssh_private_key_file=/repository/ansible/.ssh/id_rsa_ansible
Playbook:
---
- hosts: qv
become: yes
roles:
- abc
Error:
fatal: [e8-df1]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_name": "setup"
},
"module_stderr": "Shared connection to e8-df1 closed.\r\n",
"module_stdout": "sudo: a password is required\r\n",
"msg": "MODULE FAILURE"
}
fatal: [e8-df2]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_name": "setup"
},
"module_stderr": "Shared connection to e8-df2 closed.\r\n",
"module_stdout": "sudo: a password is required\r\n",
"msg": "MODULE FAILURE"
}
I have gone through some documents and Q&As and they are suggesting to add below line in the sudoers file.
ansible ALL=(ALL) NOPASSWD: ALL
Now, I am not able to realize why the shell procedure is working without the sudoers configuration. And if there is any other way to achieve the same in the ansible?