On Tuesday, March 13, 2018 at 7:35:27 AM UTC-7, Patrick Hunt wrote:Hi Patrick, > > I can help to address #2 at least for now. >> > > Ansible does not allow you to chain "Become" statements. In other words > you cannot log in as user1, become root, and then become user2 (or even > user1) in the same play. You could address this in a few different ways > that I know of: > > - split the play into multiple plays within a playbook where you can set > the become for each different play: > > --- > - host: localhost > become: true > become_user: root > become_method: su > > > tasks: > - name: some play performed as root > > > - host: localhost > become: true > become_user: user2 > become_method: su > > > tasks: > - name: some other play performed as user2 > > - host: localhost > become: false > > tasks: > - name: some other play performed as user1 > ... > > - you could also use a command module workaround (at least with a Nix > system) such as: > > --- > - hosts: localhost > become: true > become_user: root > become_method: su > > > tasks: > - name: some task as root > > > - name: some task as user2 > command: su - user2 -c "/home/user2/somecommand.sh" > ... > > > Hi Patrick,
> My follow-up question is... why? In your example you could just create > the file as root, set the owner, group, and mode to reflect the user you > want it to be. > > Thank you very much for suggesting above method and sharing your knowledge. This playbook will be used by other users in my team on their laptop. Hence creating a file and performing few tasks as the local user. Thanks, Balaji Chavdi > Hope this helps a bit. > > Thanks, > Patrick > -- 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-project+unsubscr...@googlegroups.com. To post to this group, send email to firstname.lastname@example.org. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9aee4ee9-7655-434f-bd1b-1773a0838e8e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.