I've created two very simple Ansible roles called base
and web
. web
is dependent on base
and this dependency is defined in web/meta/main.yml
.
base
has the following task defined in base/tasks/main.yml
:
- name: install required packages
apt:
name: "{{ install_packages }}"
update_cache: "{{ apt_update_cache }}"
cache_valid_time: "{{ apt_cache_valid_time }}"
The variables in base
are defined in base/defaults/main.yml
:
apt_update_cache: yes
apt_cache_valid_time: 3600
install_packages:
- ufw
- sshguard
The variables in web
are defined in web/defaults/main.yml
:
install_packages:
- nginx
What I want to do is:
- Call
install required packages
frombase
, using theinstall_packages
variable frombase
, andapt_update_cache
andapt_cache_valid_time
frombase
. - Call
install required packages
fromweb
, using theinstall_packages
variable fromweb
, andapt_update_cache
andapt_cache_valid_time
frombase
(since I haven't overridden either of those two inweb
).
Is this possible, and if so how would I go about doing it? Alternatively, is there a 'better' way to achieve the same result, without reproducing the task in every dependent role (I'm likely to create several others which depend on base
, and they will all have their own role-specific tasks too)?