I am trying to include a conditional role in my playbook, this role will only apply to first node of my server group, and this server group is automatically created, the ip/hostnames are not fixed. So we could not use following format
It’s not intended that you would need to use template expressions in the when statement (I wanted to make that not required to access variables), but it’s also true that conditional expressions in Jinja2 are not allowed the full python gamut. So that first version is probably going to throw it for a loop – and I think that’s fine, as that’s a bit too complex for the design aesthetic of ansible anyway – that is, we want to keep things simple when we can.
But I still get following errors:
fatal: [10.1.1.1] => Conditional expression must evaluate to True or False: (True) and ({% if groups.myservers[0] == inventory_hostname %} True {% else %} False {% endif %})
fatal: [10.1.1.2] => Conditional expression must evaluate to True or False: (True) and ({% if groups.myservers[0] == inventory_hostname %} True {% else %} False {% endif %})
fatal: [10.1.1.2] => Conditional expression must evaluate to True or False: (True) and ({% if groups.myservers[0] == inventory_hostname %} True {% else %} False {% endif %})
By the way, I am using ansible server version 1.2.2.