I have an Ansible role that I want to execute on particular hosts based on a certain conditions.
I want to populate the hosts
from Ansible Tower survey. Here's my playbook:
- name: HTTP Response Deploy Automation
hosts: "{% if geo == 'LHR' %}'dblhr002' {% elif geo == 'SJC' %}'dbsjc003' {% endif %}"
gather_facts: true
roles:
- http-response-deploy
I'm getting the following error when choosing LHR:
[WARNING]: Could not match supplied host pattern, ignoring: 'dblhr002'
To note that, it doesn't work when I choose to omit the quotes around the hostnames.
TLDR; need to achieve the conditionals from Ansible as below:
if geo == "LHR":
hosts: dblhr002
if geo == "SJC":
hosts: dbsjc003