Example 3
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:
list1:
- value1
- value2
- value3
tasks:
- name: This is a list
debug:
msg: "{{ list1 }}"
- name: Accessing the values using the Python syntax
debug:
msg: "{{ list1[0] }}"
- name: Accessing the values using the dot notation
debug:
msg: "{{ list1.0 }}"
Tip
Variables that represent list
type objects can be accessed using the dot notation or Python syntax by specifying the index value.
Execute the following command
ansible-playbook playbook.yml