Reputation: 11422
Currently for a given task ansible-2.x
provides an option called become_user
that allows changing the user before the task in context is run. For example:
- name: Run Django database migrations
django_manage:
command: migrate
app_path: "{{ project_path }}"
settings: "{{ django_settings_file }}"
become_user: "{{ project_user }}"
The become_user
here only applies to the task in context and does not apply to all subsequent tasks that are run after this unless become_user
is used in those tasks also explicitly. How do we become another user for a set of tasks/subsequent tasks following a given task in playbook?
Note:
I can think of one way of doing this, which is; to refactor out these set of subsequent tasks into a new role and apply that new role on a single task with become_user
set as desired. Is there any other alternative/simpler way of changing active user for subsequent tasks without putting these tasks into a separate role?
Upvotes: 7
Views: 6696