Skip to content

Example 4

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
  vars:
    dict1_alternate:
      { key1: value1, key2: value2 }
  tasks:
    - name: This is an inline dictionary
      debug:
        msg: "{{ dict1_alternate }}"
    - name: Accessing the value using the Python syntax
      debug:
        msg: "{{ dict1_alternate['key1'] }}"
    - name: Accessing the value using the dot notation
      debug:
        msg: "{{ dict1_alternate.key1 }}"

Tip

Dict type variables can also be represented in an alternate fashion.

Execute the following command

ansible-playbook playbook.yml