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: centos1
gather_facts: false
vars:
dict1:
key1: value1
key2: value2
tasks:
- name: This is a dictionary
debug:
msg: "{{ dict1 }}"
- name: Accessing the value using the Python syntax
debug:
msg: "{{ dict1['key1'] }}"
- name: Accessing the value using the dot notation
debug:
msg: "{{ dict1.key1 }}"
Tip
Variables that represent dict
type objects can be accessed using the dot notation or Python syntax by specifying the key value.
Execute the following command
ansible-playbook playbook.yml