I want to install some packages on a server. Additionally, if a certain condition is true, I want to add an extra package to the list of packages to be installed. What I would love is have this:
- name: install packages
yum: name={{ item }}
with_items: - package1
- package2
{% if condition %} - package3
{% endif %}
Now, I know that ansible doesn’t parse playbooks with the full Jinja engine (though that would be so cool). I could of course achieve this with 2 tasks:
-
name: install packages
yum: name={{ item }}
with_items: -
package1
-
package2
-
name: install packages
yum: name=package3
when: condition
But my question is: how can I achieve this with just one task?