I want something like:
if env == ‘dev’
- hosts: "{{host}}"
user: root
else if env == ‘prod’
- hosts: "{{host}}"
user: centos
How to do that?
I want something like:
if env == ‘dev’
- hosts: "{{host}}"
user: root
else if env == ‘prod’
- hosts: "{{host}}"
user: centos
How to do that?
2
Answers
Ansible uses the Jinja2 templating engine, which lets you do:
I prefer not to put these kind of decisions into the template itself, I would use something like this in the config:
Then in the template:
This also loudly fails in case the env is not dev/prod instead of silently producing an incorrect file.