Example 1
hosts.yml
centos:
hosts:
provisioner:
ansible_connection: local
centos1:
ansible_host: '192.168.77.22'
ubuntu:
hosts:
ubuntu1:
ansible_host: '192.168.77.23'
playbook.yml
- hosts: all
tasks:
- name: Jinja2 if statement
debug:
msg: >
{# This is a comment in Jinja2 -#}
{% if ansible_distribution == "CentOS" -%}
This machine runs on CentOS
{% endif %}
Tip
Jinja2
syntax can be used inside the playbooks to introduce addtional versatility.
Execute the following command
ansible-playbook playbook.yml