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

- name: Example playbook
  hosts: all
  gather_facts: false
  tasks:
    - name: Example task
      command: whoami

Tip

The setup module can generate large compuational costs when running against multiple remote hosts. In that case we can disable this functionality by adding the gather_facts: false directive to our playbook.

Execute the following command

ansible-playbook playbook.yml
Notice that the [Gathering Facts] section is missing from the log.