Skip to content

Example 2

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: Block of executed modules
      block:
        - name: Example 1
          debug:
            msg: This is Example 1
        - name: Example 2
          debug:
            msg: This is Example 2
        - name: Example 3
          debug:
            msg: This is Example 3
      when: ansible_distribution == "CentOS"

Tip

Blocks can be used to apply when and with_<lookup> directives to multiple tasks.

Execute the following command

ansible-playbook playbook.yml