How to use sudo su - in ansible 1.9.4

436 views
Skip to first unread message

rahul bhandari

unread,
Nov 1, 2015, 7:29:44 PM11/1/15
to Ansible Project

I am trying to run following cli commands on remote host through ansible; I tried using different combinations but it is not working for me; probably I might be not using correct syntax; please help.


sudo su - user1
ls -l


Command I tired: ansible -i hosts all -m shell -a "ls -l"  -b user1

Brian Coca

unread,
Nov 1, 2015, 7:30:41 PM11/1/15
to Ansible Project
read 2nd note http://docs.ansible.com/ansible/become.html, you can use
one or the other, but not both



--
Brian Coca

Vikas Kumar

unread,
Nov 1, 2015, 7:52:27 PM11/1/15
to Ansible Project
Hi Rahul,

See this example, this will execute the command as a sudo user 'vikas027'

    - name: A sudo task
      command
: whoami
      become
: yes
      become_user
: vikas027


Regards,
Vikas
Reply all
Reply to author
Forward
0 new messages