Example 6
hosts.yml
centos:
hosts:
provisioner:
ansible_connection: local
centos1:
ansible_host: '192.168.77.22'
ubuntu:
hosts:
ubuntu1:
ansible_host: '192.168.77.23'
bucket.yml
list1:
- value1
- value2
- value3
list1_alternate:
[ value1, value2, value3 ]
dict1:
key1: value1
dict1_alternate:
{ key1: value1 }
var1: var1_value
playbook.yml
- name: Example playbook
hosts: centos1
gather_facts: false
vars_files:
- bucket.yml
tasks:
- name: An external list
debug:
msg: "{{ list1[0] }}"
- name: An external inline list
debug:
msg: "{{ list1_alternate[0] }}"
- name: An external dictionary
debug:
msg: "{{ dict1.key1 }}"
- name: An external inline dictionary
debug:
msg: "{{ dict1_alternate['key1'] }}"
- name: An external variable
debug:
msg: "{{ var1 }}"
Tip
The vars_file
directive can be used to load a set of variables from an existing YAML
file.
Execute the following command
ansible-playbook playbook.yml