Skip to content

Instantly share code, notes, and snippets.

@janzenz
Last active May 24, 2016 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janzenz/8030b104c109df3b59f26d133c8af03b to your computer and use it in GitHub Desktop.
Save janzenz/8030b104c109df3b59f26d133c8af03b to your computer and use it in GitHub Desktop.
---
- hosts: web2
gather_facts: no
remote_user: vagrant
tasks:
- name: debug user 1
shell: "whoami"
- name: debug user 2
shell: "whoami"
become: yes
become_user: root
- name: debug user 3
shell: "whoami"
# Result:
# vagrant
# root
# vagrant
@bgrace
Copy link

bgrace commented May 24, 2016

Ah. This is expected behavior but I see how my answer on SO may have misled you. The new directives/command line options I referred to are set these options on a per-host or per-play basis (these are different from become/become_user, as described in the linked documentation). If you use the become directive in a task, it will indeed be scoped to that task as your gist demonstrates. Sorry for the misunderstanding. If you want to have escalation run for multiple tasks, I think you can use the include task and set the become_user directive on it—not 100% sure though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment