Reputation: 46370
I have a bunch of tasks in a role that repeatedly use:
sudo: yes
sudo_user: my_user
Isn't there a way that I can set these attributes for multiple tasks, so it will be more DRY?
I know I can change the user in the playbook, but other tasks need user root
, so I can't change that.
Upvotes: 4
Views: 335
Reputation: 1958
In your inventory file you can have multiple groups, ie: root_access group or deploy_user group. So you define your hosts, say like 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 the inventory groups.
Upvotes: 1