Skip to content

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

- name: Example playbook
  hosts: all
  gather_facts: false
  vars:
    var1: var1_value
  tasks:
    - debug:
        msg: "This is the value of var1: {{ var1 }}"

Tip

Variables can be defined in the playbook's scope by using the vars directive.

Execute the following command

ansible-playbook playbook.yml