Last active
May 14, 2023 12:25
-
-
Save zeitounator/0e7a0320fbd157b47ea51b1d3397453e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat inventory.yml | |
--- | |
cloud1: | |
vars: | |
ansible_user: specific_service_user | |
hosts: | |
host1: | |
host2: | |
cloud2: | |
vars: | |
ansible_user: admin | |
host: | |
host3: | |
host4: | |
cloud3: | |
vars: | |
ansible_user: root | |
hosts: | |
host5: | |
host6: | |
$ cat dummy_example.yml | |
--- | |
- name: An entire play as root | |
hosts: all | |
become: true | |
tasks: | |
- name: install a package | |
package: | |
name: vim | |
state: present | |
- name: An entire play as arbitrary user | |
hosts: all | |
become_user: postgres | |
become: true | |
tasks: | |
- name: Do something as postgres | |
lineinfile: | |
dest: /var/lib/postgres/{{ postgres_version }}/postgres.conf | |
line: "# a dummy line" | |
- name Specific tasks as different users | |
hosts: all | |
tasks: | |
- name: run as connection user | |
shell: id -a | |
register: as_normal | |
- name: run as root | |
become: true | |
shell: id -a | |
register: as_root | |
- name: run as someone | |
become_user: someone | |
become: true | |
shell: id -a | |
register as_someone | |
- name: show all resulst from above | |
debug: | |
var: "{{ item }}" | |
loop: | |
- as_normal | |
- as_root | |
- as_someone | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment