Multiple tasks with the same sudo_user as Ansible?

I have many tasks in a role that is reused:

sudo: yes
sudo_user: my_user

There is no way I can set these attributes for multiple tasks, so will it be drier?

I know that I can change the user in the playbook, but other tasks need a user root, so I can’t change him.

+4
source share
1 answer

You can have several groups in your inventory file, that is, the root_access group or the deploy_user group. So, you define your hosts, let's say this:

[web]
webby-1 ansible_ssh_host=192.168.1.1
webby-2 ansible_ssh_host=ec2-192-168-1-1.compute-1.amazonaws.com

[foo:children]
web

[foo:vars]
ansible_ssh_user=foo
ansible_ssh_private_key_file=~/.ssh/foo.pem

[bar:children]
web

[bar:vars]
ansible_ssh_user=bar
ansible_ssh_private_key_file=~/.ssh/bar.pem

and then you can call them based on inventory groups.

+1
source

Source: https://habr.com/ru/post/1541261/


All Articles