is it possible on remote as 'root' then 'su - uid' to run a few commands

34 views
Skip to first unread message

weichi cheng

unread,
Jul 28, 2014, 11:16:50 AM7/28/14
to ansible...@googlegroups.com
Just go through a few tutorials of Ansible and am trying to see if I can use it to replace our 'tcl expect' template engine in house.

We have an internal server inside a isolated domain that have 'root' access to most of the internal boxes from other domains.
The template engine's job is to execute commands supplied in a file and run as uid that will be input to the template engine also. The template engine either successfully run all commands or stop at the first failed command and return error and output.

a simple test like below hang forever. 

  ---
  - hosts: host1
    user: root
    tasks:
      - name: run as user1 on host1 and with ls -l
        shell: "su - user1; ls -l" 


Is this kind of task achievable?

Thanks for any insight!
Jack Cheng

Michael DeHaan

unread,
Jul 28, 2014, 8:42:35 PM7/28/14
to ansible...@googlegroups.com
su in ansible doesn't look like that.   

Be sure you have set user appropriately, but you should use the native su or sudo constructs.  sudo is preferred, but su works as well.

  ---
  - hosts: host1
    su: True
    su_user: user1
    tasks:
      - name: run ls -l
        shell: "ls -l" 

There's various reasons for the machinery, but a lot of it has do how modules are transferred.

In Ansible, you should avoid interactive commands, and you'll probably need to specify --ask-su-pass or --ask-sudo-pass as appropriate.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7cac515a-ab6f-4069-b39e-dce88485395e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages