-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbootstrap.yml
274 lines (253 loc) · 7.67 KB
/
bootstrap.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
---
- hosts: all
remote_user: vagrant
vars:
alpine_packages:
- alpine-sdk
- libffi-dev
- openssl-dev
- py-setuptools
ansible_ver: 2.2.0.0
debian_packages:
- build-essential
- libffi-dev
- libssl-dev
- python-dev
- python-pip
- python-setuptools
host_vars_directory: ./host_vars
host_vars_file: '{{ host_vars_directory }}/{{ inventory_hostname }}.yml'
pri_domain_name: vagrant.local
redhat_packages:
- gmp-devel
- libffi-devel
- openssl-devel
- python-crypto
- python-devel
- python-pip
- python-setuptools
- redhat-rpm-config
ssh_key_path: '.vagrant/machines/{{ inventory_hostname }}/virtualbox/private_key'
suse_packages:
- gmp-devel
- libffi-devel
- openssl-devel
- python-crypto
- python-devel
- python-pip
- python-setuptools
update_host_vars: true
roles:
tasks:
# Update apt-cache to ensure up to date
- name: Updating Apt Cache (Debian)
apt:
update_cache: yes
cache_valid_time: 3600
become: true
when: ansible_os_family == "Debian"
# Install pre-reqs for Ansible install
- name: Installing Ansible Pre-Reqs (Alpine)
apk:
name: "{{ item }}"
state: "present"
become: true
with_items: '{{ alpine_packages }}'
when: ansible_os_family == "Alpine"
- name: Installing Python Packages (Alpine)
apk:
name: "{{ item }}"
state: "present"
become: true
with_items:
- py-pip
- python-dev
when: >
ansible_os_family == "Alpine" and
ansible_distribution_version < '3.5'
- name: Installing Python Packages (Alpine)
apk:
name: "{{ item }}"
state: "present"
become: true
with_items:
- py2-pip
- python2-dev
when: >
ansible_os_family == "Alpine" and
ansible_distribution_version >= '3.5'
# Install pre-reqs for Ansible install
- name: Installing Ansible Pre-Reqs (Debian)
apt:
name: "{{ item }}"
state: "present"
become: true
with_items: '{{ debian_packages }}'
when: ansible_os_family == "Debian"
- name: Installing EPEL Repo (RedHat)
yum:
name: "epel-release"
state: "present"
become: true
when: >
ansible_os_family == "RedHat" and
ansible_distribution != "Fedora"
# Install pre-reqs for Ansible install
- name: Installing Ansible Pre-Reqs (RedHat)
yum:
name: "{{ item }}"
state: "present"
become: true
with_items: '{{ redhat_packages }}'
when: >
ansible_os_family == "RedHat" and
ansible_distribution != "Fedora"
# Install pre-reqs for Ansible install
- name: Installing Ansible Pre-Reqs (Fedora)
dnf:
name: "python-dnf"
state: "present"
become: true
when: >
ansible_os_family == "RedHat" and
ansible_distribution == "Fedora"
# Install pre-reqs for Ansible install
- name: Installing Ansible Pre-Reqs (Fedora)
dnf:
name: "{{ item }}"
state: "present"
become: true
with_items: '{{ redhat_packages }}'
when: >
ansible_os_family == "RedHat" and
ansible_distribution == "Fedora"
# Install pre-reqs for Ansible install
- name: Installing Ansible Pre-Reqs (openSUSE)
zypper:
name: "{{ item }}"
state: "present"
become: true
with_items: '{{ suse_packages }}'
when: ansible_os_family == "Suse"
# Upgrading these packages to ensure a successful Ansible install
- name: Updating Python Modules
pip:
name: "{{ item }}"
state: "latest"
become: true
with_items:
- pip
- cffi
# Install Ansible to run Ansible related tasks within guest
- name: Installing Ansible
pip:
name: "ansible"
state: "present"
version: "{{ ansible_ver }}"
become: true
# Check/create host_vars on localhost
- name: Ensuring host_vars Directory Exists
file:
path: "./host_vars"
state: "directory"
delegate_to: "localhost"
run_once: true
become: false
when: >
update_host_vars is defined and
update_host_vars
- name: Ensuring Host File Exists In host_vars
stat:
path: "{{ host_vars_file }}"
delegate_to: "localhost"
register: "host_var"
become: false
when: >
update_host_vars is defined and
update_host_vars
- name: Creating Missing host_vars
file:
path: "{{ host_vars_file }}"
state: "touch"
delegate_to: "localhost"
become: false
when: not host_var['stat']['exists']
- name: Updating ansible_ssh_host
lineinfile:
dest: "{{ host_vars_file }}"
regexp: "^ansible_ssh_host{{ ':' }}"
line: "ansible_ssh_host{{ ':' }} {{ ansible_eth1['ipv4']['address'] }}"
delegate_to: "localhost"
become: false
register: "ansible_host_updated_eth1"
when: >
ansible_os_family != "Alpine" and
(update_host_vars is defined and
update_host_vars) and
(ansible_eth1 is defined and
ansible_eth1['ipv4']['address'] is defined)
- name: Updating ansible_ssh_host
lineinfile:
dest: "{{ host_vars_file }}"
regexp: "^ansible_ssh_host{{ ':' }}"
line: "ansible_ssh_host{{ ':' }} {{ ansible_enp0s8['ipv4']['address'] }}"
delegate_to: "localhost"
become: false
register: "ansible_host_updated_enp0s8"
when: >
ansible_os_family != "Alpine" and
(update_host_vars is defined and
update_host_vars) and
(ansible_enp0s8 is defined and
ansible_enp0s8['ipv4']['address'] is defined)
- name: Capturing eth1 IP Address (Alpine)
shell: "ifconfig eth1 | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}'"
register: "_alpine_eth1_ip"
become: true
when: ansible_os_family == "Alpine"
- name: Updating ansible_ssh_host (Alpine)
lineinfile:
dest: "{{ host_vars_file }}"
regexp: "^ansible_ssh_host{{ ':' }}"
line: "ansible_ssh_host{{ ':' }} {{ _alpine_eth1_ip['stdout'] }}"
delegate_to: "localhost"
become: false
register: "ansible_host_updated_alpine"
when: >
(update_host_vars is defined and
update_host_vars) and
ansible_os_family == "Alpine"
- name: Updating ansible_ssh_port
lineinfile:
dest: "{{ host_vars_file }}"
regexp: "^ansible_ssh_port{{ ':' }}"
line: "ansible_ssh_port{{ ':' }} 22"
delegate_to: "localhost"
become: false
when: >
(update_host_vars is defined and
update_host_vars) and
(ansible_host_updated_eth1['changed'] or
ansible_host_updated_enp0s8['changed'] or
ansible_host_updated_alpine['changed'])
- name: Updating ansible_ssh_key
lineinfile:
dest: "{{ host_vars_file }}"
regexp: "^ansible_ssh_private_key_file{{ ':' }}"
line: "ansible_ssh_private_key_file{{ ':' }} {{ ssh_key_path }}"
delegate_to: "localhost"
become: false
when: >
update_host_vars is defined and
update_host_vars
- name: Ensuring host_vars Is YAML Formatted
lineinfile:
dest: "{{ host_vars_file }}"
regexp: "---"
line: "---"
insertbefore: "BOF"
delegate_to: "localhost"
become: false
when: >
update_host_vars is defined and
update_host_vars