>
> 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"
...


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.

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 ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a3e6f37a-aaa6-439d-9ef0-2388c6e76e65%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to