How to switch a user per task or set of tasks

0 votes

Hi Guys,

I have created an Ansible Playbook. This playbook contains some tasks. I want to run the tasks according to the user. How can I achieve that?

Sep 17, 2020 in Ansible by akhtar
• 38,210 points
343 views

1 answer to this question.

0 votes

Hi@akhtar,

Ansible has a concept of privilege escalation. Ansible uses directives to achieve it. You can specify a user to run your task as shown below.

- hosts: Httpd
  remote_user: root/apache
  tasks:
  - name: Start service
    service:
      name: httpd
      state:started
    remote_user: name
answered Sep 17, 2020 by MD
• 95,300 points

Related Questions In Ansible

0 votes
1 answer

How to skip execution of a task in ansible playbook ??

Define tags...  Then while running playbook use --skip-tags. READ MORE

answered Sep 30, 2020 in Ansible by Adil
4,284 views
0 votes
1 answer

How do I handle different machines needing different user accounts or ports to log in with?

Setting inventory variables in the inventory file ...READ MORE

answered Jan 31, 2019 in Ansible by Ansi
198 views
0 votes
1 answer

How to overwrite the content of a file in remote systems using Ansible playbook?

Hi@akhtar, You can find one argument in the ...READ MORE

answered Aug 2, 2020 in Ansible by MD
• 95,300 points
4,811 views
0 votes
1 answer

How to give a task name in Ansible?

Hi@akhtar, You can give the task name in ...READ MORE

answered Aug 2, 2020 in Ansible by MD
• 95,300 points
1,129 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
1,289 views
+2 votes
1 answer
0 votes
1 answer

How to capture the output of a task in Ansible Playbook?

Hi@akhtar, Ansible registers module used to capture/store the ...READ MORE

answered Aug 2, 2020 in Ansible by MD
• 95,300 points
6,564 views
0 votes
1 answer

How to create a group of Managed Nodes in Ansible?

Hi@akhtar, You can use tags in your inventory ...READ MORE

answered Aug 1, 2020 in Ansible by MD
• 95,300 points
223 views