I have to build a cluster where certain packages should be installed on all hosts while other packages are installed on specific hosts only.
I wish to add a conditional to my yum install loop to select the target host based on my inventory groups (master, slave, all).
- name: Install Package
when: inventory_hostname in groups[ {{item.host }} ]
yum:
name: "{{ item.name }}"
state: present
loop:
- {name: 'package_1', host: 'master'}
- {name: 'package_2', host: 'slave'}
- {name: 'package_3', host: 'all'}
I understand that jinja2 templating is not an option, but I couldn't find what is the right way to do it. Thanks!