If you want different tasks to be run with different users you can use become and become_user.
Hey,I want to know if possible use a lot of user for ansible.Exemple, if i use ansible_user=user1, user2because i want to use serial: 1And i want that ansible use firt user1 and secondaly user2If possible or not please ??Regards,
Hey,I want to know if possible use a lot of user for ansible.
Exemple, if i use ansible_user=user1, user2because i want to use serial: 1
---
- hosts: localhost
gather_facts: no
tasks:
- name: Run a command as stephen.maher
command: whoami
become: yes
become_method: sudo
become_user: stephen.maher
register: output
- debug:
var: output.stdout_lines
- name: Run a command as root
command: whoami
become: yes
become_method: sudo
become_user: root
register: output
- debug:
var: output.stdout_lines
$ ansible-playbook test.yml
PLAY [localhost] ***********************************************************************************************************************************************************************************************
TASK [Run a command as stephen.maher] **************************************************************************************************************************************************************************
changed: [localhost]
TASK [debug] ***************************************************************************************************************************************************************************************************
ok: [localhost] => {
"output.stdout_lines": [
"stephen.maher"
]
}
TASK [Run a command as nobody] *********************************************************************************************************************************************************************************
changed: [localhost]
TASK [debug] ***************************************************************************************************************************************************************************************************
ok: [localhost] => {
"output.stdout_lines": [
"root"
]
}
PLAY RECAP *****************************************************************************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
--
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-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1aeb59b1-aff3-44a6-b530-b2284013169e%40googlegroups.com.
Regards,
stephe...@ocado.com | 0777 5832553
UNIX Engineer
Ocado Technology, Buildings One & Two, Trident Place, Mosquito Way, Hatfield, Hertfordshire,
AL10 9UL
Need some work done by any of the Infrastructure Teams? Click here!
Notice:
This email is confidential and may contain copyright material of members of the Ocado Group. Opinions and views expressed in this message may not necessarily reflect the opinions and views of the members of the Ocado Group.
If you are not the intended recipient, please notify us immediately and delete all copies of this message. Please note that it is your responsibility to scan this message for viruses.
References to the "Ocado Group" are to Ocado Group plc (registered in England and Wales with number 7098618) and its subsidiary undertakings (as that expression is defined in the Companies Act 2006) from time to time. The registered office of Ocado Group plc is Buildings One & Two, Trident Place, Mosquito Way, Hatfield, Hertfordshire, AL10 9UL.