I would like to add an item to a list in ansible dependent on some condition being met.
This doesn\'t work:
some_dictionary:
app:
- some
Is there a reason you have to do everything in one go?
This is pretty easy if you specify the additional item(s) to add in separate vars, as you can just do list1 + list2.
---
- hosts: localhost
gather_facts: False
connection: local
vars:
mylist:
- one
- two
mycondition: False
myconditionalitem: foo
tasks:
- debug:
msg: "{{ mylist + [myconditionalitem] if mycondition else mylist }}"