-
Notifications
You must be signed in to change notification settings - Fork 32
/
prep_host_vars.yml
188 lines (174 loc) · 5.8 KB
/
prep_host_vars.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
---
- hosts: all
gather_facts: false
vars:
group_vars_dir: "{{ working_dir + '/' + vagrant_dir + '/group_vars' }}"
host_vars_dir: "{{ working_dir + '/' + vagrant_dir + '/host_vars' }}"
nodes: "{{ (lookup('file', working_dir + '/environment.yml')|from_yaml)['nodes'] }}"
vagrant_dir: .vagrant/provisioners/ansible/inventory
working_dir: "{{ lookup('env', 'PWD') }}"
tasks:
- name: Ensuring group_vars Directory Exists
file:
path: "{{ group_vars_dir }}"
state: directory
delegate_to: localhost
run_once: true
- name: Ensuring host_vars Directory Exists
file:
path: "{{ host_vars_dir }}"
state: directory
delegate_to: localhost
run_once: true
- name: Ensuring Host File Exists In host_vars
stat:
path: "{{ host_vars_dir }}/{{ item['name'] }}.yml"
delegate_to: localhost
run_once: true
register: host_var
with_items: "{{ nodes }}"
- name: Creating Missing host_vars
file:
path: "{{ host_vars_dir }}/{{ item['item']['name'] }}.yml"
state: touch
delegate_to: localhost
run_once: true
with_items: "{{ host_var['results'] }}"
when: not item['stat']['exists']
- name: Updating ansible_host
lineinfile:
dest: "{{ host_vars_dir }}/{{ item['name'] }}.yml"
regexp: "^ansible_host{{ ':' }}"
state: absent
delegate_to: localhost
run_once: true
with_items: "{{ nodes }}"
when: >
(item['interfaces'] is defined and
item['interfaces'] == []) or
item['interfaces'] is not defined
- name: Updating ansible_host
lineinfile:
dest: "{{ host_vars_dir }}/{{ item['name'] }}.yml"
regexp: "^ansible_host{{ ':' }}"
line: "ansible_host{{ ':' }} {{ item['interfaces'][0]['ip'] }}"
state: present
delegate_to: localhost
run_once: true
with_items: "{{ nodes }}"
when: >
item['interfaces'] is defined and
item['interfaces'] != [] and
item['interfaces'][0]['auto_config']
- name: Updating ansible_port
lineinfile:
dest: "{{ host_vars_dir }}/{{ item['name'] }}.yml"
regexp: "^ansible_port{{ ':' }}"
state: absent
delegate_to: localhost
run_once: true
with_items: "{{ nodes }}"
when: >
(item['interfaces'] is defined and
item['interfaces'] == []) or
item['interfaces'] is not defined
- name: Updating ansible_port
lineinfile:
dest: "{{ host_vars_dir }}/{{ item['name'] }}.yml"
regexp: "^ansible_port{{ ':' }}"
line: "ansible_port{{ ':' }} 22"
state: present
delegate_to: localhost
run_once: true
with_items: "{{ nodes }}"
when: >
(item['interfaces'] is defined and
item['interfaces'] != [] and
item['interfaces'][0]['auto_config']) and
((item['windows'] is defined and
not item['windows']) or
item['windows'] is not defined)
- name: Updating ansible_port
lineinfile:
dest: "{{ host_vars_dir }}/{{ item['name'] }}.yml"
regexp: "^ansible_port{{ ':' }}"
line: "ansible_port{{ ':' }} 5986"
state: present
delegate_to: localhost
run_once: true
with_items: "{{ nodes }}"
when: >
(item['interfaces'] is defined and
item['interfaces'] != [] and
item['interfaces'][0]['auto_config']) and
(item['windows'] is defined and
item['windows'])
- name: Updating ansible_connection
lineinfile:
dest: "{{ host_vars_dir }}/{{ item['name'] }}.yml"
regexp: "^ansible_connection{{ ':' }}"
state: absent
delegate_to: localhost
run_once: true
with_items: "{{ nodes }}"
when: >
(item['windows'] is defined and
not item['windows']) or
item['windows'] is not defined
- name: Updating ansible_connection
lineinfile:
dest: "{{ host_vars_dir }}/{{ item['name'] }}.yml"
regexp: "^ansible_connection{{ ':' }}"
line: "ansible_connection{{ ':' }} winrm"
state: present
delegate_to: localhost
run_once: true
with_items: "{{ nodes }}"
when: >
(item['windows'] is defined and
item['windows'])
- name: Updating ansible_winrm_server_cert_validation
lineinfile:
dest: "{{ host_vars_dir }}/{{ item['name'] }}.yml"
regexp: "^ansible_winrm_server_cert_validation{{ ':' }}"
state: absent
delegate_to: localhost
run_once: true
with_items: "{{ nodes }}"
when: >
(item['windows'] is defined and
not item['windows']) or
item['windows'] is not defined
- name: Updating ansible_winrm_server_cert_validation
lineinfile:
dest: "{{ host_vars_dir }}/{{ item['name'] }}.yml"
regexp: "^ansible_winrm_server_cert_validation{{ ':' }}"
line: "ansible_winrm_server_cert_validation{{ ':' }} ignore"
state: present
delegate_to: localhost
run_once: true
with_items: "{{ nodes }}"
when: >
(item['windows'] is defined and
item['windows'])
- name: Updating ansible_user
lineinfile:
dest: "{{ host_vars_dir }}/{{ item['name'] }}.yml"
regexp: "^ansible_user{{ ':' }}"
line: "ansible_user{{ ':' }} vagrant"
state: present
delegate_to: localhost
run_once: true
with_items: "{{ nodes }}"
- name: Updating ansible_password
lineinfile:
dest: "{{ host_vars_dir }}/{{ item['name'] }}.yml"
regexp: "^ansible_password{{ ':' }}"
line: "ansible_password{{ ':' }} vagrant"
state: present
delegate_to: localhost
run_once: true
with_items: "{{ nodes }}"
when: >
(item['windows'] is defined and
item['windows'])