-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook-varspractice01.yml
62 lines (53 loc) · 1.93 KB
/
playbook-varspractice01.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
- name: Learning to work with variable data
hosts: localhost # only use local host if you're connecting to a single storage device
connection: local # when we connect to storage devices, we typically choose local
gather_facts: false # when we connect to a storage device, we typically set this to false
# play variables
vars:
# this is a variable
servers:
- poweredge001
- poweredge002
- poweredge003
- poweredge004
- poweredge005
# this is a variable
locations:
# this variable is a child of locations
regions:
- northeast
- north
- northwest
# this variable is a child of locations
datacenters:
- Hershey Pennsylvania
- Rochester New York
- Seattle Washington
# tasks (python modules to execute)
tasks:
# 1st item in the servers list
- name: Print out the name poweredge001
ansible.builtin.debug:
var: servers[0]
# display all datacenters
- name: Print out ALL datacenters
ansible.builtin.debug:
var: locations.datacenters # var is mutually exclusive with msg
# msg: "{{ locations.datacenters }}" # use msg if you want to include other text
# second item in the regions list
- name: Print out north
ansible.builtin.debug:
msg: "{{ locations.regions[1] }}"
# use a loop to display all of the regions with a loop
- name: Print out all regions
ansible.builtin.debug:
var: item
loop: "{{ locations.regions }}"
# fourth item in the servers list is actually the 3rd item as numbering begins at 0
- name: Print out the fourth volume in the list
ansible.builtin.debug:
var: servers[3]
- name: Lists may be combined as they are the same type
ansible.builtin.debug:
var: item
loop: "{{ locations.regions + locations.datacenters }}" # combine both lists into a single list