# ansible doubt

**URL:** <https://forum.ansible.com/t/ansible-doubt/25107>\
**Category:** Ansible Project\
**Created:** [July 27, 2017, 1:25pm UTC](https://forum.ansible.com/t/ansible-doubt/25107 "2017-07-27T13:25:46Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [July 27, 2017, 1:25pm UTC](https://forum.ansible.com/t/ansible-doubt/25107/1 "2017-07-27T13:25:46Z")

</div>

Hello Team,

Can some one tell me do we need user to b in /etc/sudoers file of all servers if we wish to execute /sbin/vgs command on all servers.

also how can we we store global username password variable for ansible which is accesible for all other ansible components.

---

<div class="post-metadata">

**Author:** ![Andrew\_Latham](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@Andrew\_Latham](https://forum.ansible.com/u/Andrew_Latham)\
**Post date:** [July 27, 2017, 1:40pm UTC](https://forum.ansible.com/t/ansible-doubt/25107/2 "2017-07-27T13:40:30Z")

</div>

Sameer

There are various ways to become ( [http://docs.ansible.com/ansible/latest/become.html#directives](http://docs.ansible.com/ansible/latest/become.html#directives) ) and sudo is just one of them. So no you don’t have to add a user to all systems sudoers file but I would hope you have a directory service that manages this for you.

The vault would be good for storing passwords and managing them [http://docs.ansible.com/ansible/latest/playbooks\_vault.html](http://docs.ansible.com/ansible/latest/playbooks_vault.html)

---

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [July 27, 2017, 7:31pm UTC](https://forum.ansible.com/t/ansible-doubt/25107/3 "2017-07-27T19:31:34Z")

</div>

When i use following command it aks me two passwords one ssh and other one for sudo. It should only asks password once as it is same password  
ansible -k -m shell -a “/sbin/vgs” all

Below is the ansible.cfg config.

[privilege\_escalation]  
become=True  
become\_method=sudo  
become\_user=root  
become\_ask\_pass=False — If this is false then why it is asking me the password.

It returns module failed if user smodak is not in sudoers file

ansible -b -k -m shell -a “/sbin/vgs” all  
SSH password:  
SUDO password[defaults to SSH password]:  
NESBWDA01 | FAILED | rc=0 \>\>  
MODULE FAILURE -----\>

How to get the output even if user is not in sudoers file

---

<div class="post-metadata">

**Author:** ![Andrew\_Latham](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@Andrew\_Latham](https://forum.ansible.com/u/Andrew_Latham)\
**Post date:** [July 27, 2017, 7:44pm UTC](https://forum.ansible.com/t/ansible-doubt/25107/4 "2017-07-27T19:44:59Z")

</div>

Sameer

I am making assumptions about what you are attempting to do but try [http://lathama.com/post/ansible-one-liners](http://lathama.com/post/ansible-one-liners) and an example inventory I have for testing is  
‘’’  
[local]  
localhost ansible\_python\_interpreter=/usr/bin/python3 ansible\_user=lathama ansible\_become=root ansible\_become\_method=su  
‘’’

---

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [July 28, 2017, 10:30am UTC](https://forum.ansible.com/t/ansible-doubt/25107/5 "2017-07-28T10:30:15Z")

</div>

I tried with given command but it does not work.

I will repeat my question. My question is we have 20 servers in inventory file and i want /sbin/vgs data using below command

ansible -b -k -m shell -a “/sbin/vgs” all

Now out of 20 server 2 servers does not have smodak account in /etc/sudoers file so i m getting below error for those

SUDO password[defaults to SSH password]:  
NESBWDA01 | FAILED | rc=0 \>\>  
MODULE FAILURE

How we can resolve this without adding smodak account in /etc/sudoers

---

<div class="post-metadata">

**Author:** ![azaghal](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/azaghal/32/4743_2.png) [@azaghal](https://forum.ansible.com/u/azaghal)\
**Post date:** [July 28, 2017, 12:08pm UTC](https://forum.ansible.com/t/ansible-doubt/25107/6 "2017-07-28T12:08:52Z")

</div>

Not sure why you wouldn't set-up sudoers for somethings like this,  
but...

If you have a look at output of ansible --help you will notice there is  
a couple of different arguments related to switching users.

In your case, you should try running something similar to:

ansible --ask-become-pass --become-method su -b -k -m shell -a "/sbin/vgs" all

This will prompt you for two passwords - one for SSH connection, and  
one for the \_root\_ user.

Best regards

---

<div class="post-metadata">

**Author:** ![jean-yves](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@jean-yves](https://forum.ansible.com/u/jean-yves)\
**Post date:** [July 28, 2017, 12:09pm UTC](https://forum.ansible.com/t/ansible-doubt/25107/7 "2017-07-28T12:09:06Z")

</div>

Hi,

/sbin/vgs command need to be root  
So you need sudo or root direct access to use this command  
ansible is not that magic... if you can't do it with shell, you can't do  
it via ansible

Regards,

JYL

---

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [July 28, 2017, 3:26pm UTC](https://forum.ansible.com/t/ansible-doubt/25107/8 "2017-07-28T15:26:30Z")

</div>

Hello Team,

when i run below command without -k switch it asks for one sudo password and fails on all server.  
[smodak@hel-shell-2 tasks]$ ansible all -a “/bin/date”  
SUDO password:  
NESECDA01 | UNREACHABLE! =\> {  
“changed”: false,  
“msg”: “Failed to connect to the host via ssh: Permission denied (publickey,keyboard-interactive).\r\n”,  
“unreachable”: true  
}  
NESGRDDB01 | UNREACHABLE! =\> {  
“changed”: false,  
“msg”: “Failed to connect to the host via ssh: _ **\n\t\t\t\t\t\t\t\t\n\tName: Suse-11-SP4-Template \t \n \t\t\t\t\t\t\t\t\n\tType: VMware guest @ R10\t\t\t\t\n\t\t\t\t\t\t\t\t\n\tAuthorized uses only. \t\t\t\t\t\n\tAll activity may be monitored and reported.\t\t\t\n\t\t\t\t\t\t\t\t\n** _\*\*\*\*\*\*\*\*\*\*\*\*\*\*\nPermission denied (publickey,keyboard-interactive).\r\n”,  
“unreachable”: true  
}

But i run as following ansible all -k -a “/bin/date” . It runs well for other server except one server where it(user) does not have sudo permission on server.

[smodak@hel-shell-2 tasks]$ ansible all -k -a “/bin/date”  
SSH password:  
SUDO password[defaults to SSH password]:  
NESBWDA01 | FAILED | rc=0 \>\>  
MODULE FAILURE

Why does not ansible handles by its own if which server require sudo password or which does not.  
Also why even for /bin/date it requires sudo permission. Even it should run correctly on server where it does not have sudo permission as this command does not require sudo permission.

---

<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:** [July 28, 2017, 7:31pm UTC](https://forum.ansible.com/t/ansible-doubt/25107/9 "2017-07-28T19:31:28Z")

</div>

> when i run below command without -k switch it asks for one sudo password  
> and fails on all server.  
> [smodak@hel-shell-2 tasks]$ ansible all -a "/bin/date"  
> SUDO password:  
> NESECDA01 | UNREACHABLE! =\> {

Since you host require a password it will of course fail if you do not provide one.

> But i run as following ansible all -k -a "/bin/date" . It runs well for  
> other server except one server where it(user) does not have sudo permission  
> on server.
> 
> [smodak@hel-shell-2 tasks]$ ansible all -k -a "/bin/date"  
> SSH password:  
> SUDO password[defaults to SSH password]:  
> NESBWDA01 | FAILED | rc=0 \>\>  
> MODULE FAILURE
> 
> Why does not ansible handles by its own if which server require sudo  
> password or which does not.

Ansible does what you say it to do, run sudo, Ansible don't guess what you are trying to do. It run what you say it should do.

> Also why even for /bin/date it requires sudo permission. Even it should run  
> correctly on server where it does not have sudo permission as this command  
> does not require sudo permission.

It don't require sudo.

But somewhere in your configuration like ansible.cfg you have become\_ask\_pass = True and/or ask\_sudo\_pass = True  
That is why Ansible ask for sudo password even without -K on the command line.

---

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [July 29, 2017, 6:45pm UTC](https://forum.ansible.com/t/ansible-doubt/25107/10 "2017-07-29T18:45:04Z")

</div>

Thanks for clearing my doubts.

This will encourage me to dig more.
