Example 5
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 for loop
debug:
msg: >
{% for entry in ansible_all_ipv4_addresses -%}
IPv4 address {{ loop.index }} = {{ entry }}
{% endfor %}
Tip
Jinja2
allows the user to create complex loops in task
scope.
Execute the following command
ansible-playbook playbook.yml