Skip to content

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

- name: Example playbook
  hosts: centos1
  gather_facts: false
  tasks:
    - name: Task1
      debug:
        msg: This is Task1
      tags:
        - task1
    - name: Task2
      debug:
        msg: This is Task2
      tags:
        - task2

Tip

Tags can be used to add additional grouping to tasks, playbooks and roles.

Execute the following command

ansible-playbook playbook.yml

Bonus round

Check the ansible-playbook CLI options and

  • execute only tasks that contain the task1 tag
  • exclude all tasks taht have the task1 tag