-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.yml
287 lines (239 loc) · 8.43 KB
/
configure.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
275
276
277
278
279
280
281
282
283
284
285
---
- hosts: nodes
gather_facts: no
vars:
packages:
- build-essential
- dkms
- unzip
- wget
PHPpackages:
- apache2
- php
- php-mysql
- libapache2-mod-php
- php-soap
- php-xml
# oracle_key_file: "{{ ansible_env.HOME }}/oraclekey/oracle_key"
tasks:
- name: install python 2
raw: test -e /usr/bin/python || (sudo apt -y update && sudo apt install -y python-minimal)
- name: wait for SSH to respond on all hosts
local_action: wait_for port=22
- name: gather facts
setup:
# Rest of tasks after installing python on the machine
- name: update apt-get
become: yes
apt:
upgrade: dist
update_cache: yes
- name: install packages
become: yes
apt:
pkg: "{{ item }}"
state: present
update_cache: yes
with_items: "{{ packages }}"
# emit a debug message with each package
- debug:
msg: "{{ item }}"
with_items: "{{packages}}"
- name: restart server
shell: sleep 2 && shutdown -r now
async: 1
poll: 0
become: yes
become_method: sudo
ignore_errors: true
- pause:
seconds: 30
- name: waiting for server to come back after reboot
local_action: wait_for host={{ ansible_ssh_host }} state=started port=22 delay=30 timeout=300 connect_timeout=15
- name: add deb xenial main restricted line to sources.list
become: yes
lineinfile:
path: /etc/apt/sources.list
line: 'deb http://security.ubuntu.com/ubuntu xenial-security main restricted'
- name: add deb xenial universe line to sources.list
become: yes
lineinfile:
path: /etc/apt/sources.list
line: 'deb http://security.ubuntu.com/ubuntu xenial-security universe'
- name: add deb xenial multiverse line to sources.list
become: yes
lineinfile:
path: /etc/apt/sources.list
line: 'deb http://security.ubuntu.com/ubuntu xenial-security multiverse'
# - name: add oracle box repository to sources.list
# become: yes
# lineinfile:
# path: /etc/apt/sources.list
# line: 'deb http://download.virtualbox.org/virtualbox/debian xenial contrib'
- name: add oracle key to apt key
become: yes
apt_key:
url: "https://www.virtualbox.org/download/oracle_vbox_2016.asc"
state: present
- name: Add VirtualBox repo
become: yes
apt_repository:
repo: 'deb http://download.virtualbox.org/virtualbox/debian xenial contrib'
state: present
update_cache: yes
- name: sudo apt-get update
become: yes
apt:
upgrade: dist
update_cache: yes
- name: install virtualbox
become: yes
apt:
name: virtualbox-5.0
state: present
force: yes
update_cache: yes
# - name: make new user and add to virtualbox users
# become: yes
# user:
# name: vbuser
# createhome: yes
# shell: '/bin/bash'
# state: present
# append: yes # append groups
# groups: vboxusers
# update_password: on_create # only touch PW on user creation
# password: $6$12346789$LOJiuxAUNIEROWh9H4rZ6Stctr1huDh7UT4uzN5yx/tjmTGIlMb4CXNSdRfKPZWaNjR5rgX1ixKcveEE8REFU. #'pass' hashed using mkpasswd --method=sha-512 pass -s "12346789"
# Use the same Ubuntu user and change the password, not make a new user
- name: make new user and add to virtualbox users
become: yes
user:
name: ubuntu
state: present
append: yes # append groups
groups: vboxusers
update_password: always
password: $6$12346789$LOJiuxAUNIEROWh9H4rZ6Stctr1huDh7UT4uzN5yx/tjmTGIlMb4CXNSdRfKPZWaNjR5rgX1ixKcveEE8REFU. #'pass' hashed using mkpasswd --method=sha-512 pass -s "12346789"
- name: start the vboxdrv service
become: yes
systemd: state=started name=vboxdrv
# - name: Check if virtualbox kernel modules are loaded or not
# become: yes
# shell: "/etc/init.d/vboxdrv status"
# register: vbKerMod
#just see what is in the variable vbKerMod to confirm the modules are loaded
# - debug:
# var: vbKerMod
# # only run setup if the modules are NOT loaded
# - name: setup virtualbox kernals if not loaded
# become: yes
# shell: "/etc/init.d/vboxdrv setup"
# when: 'vbKerMod.stdout != "VirtualBox kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) are loaded."'
- name: get extensions for virtual box
become: yes
get_url:
url: http://download.virtualbox.org/virtualbox/5.0.24/Oracle_VM_VirtualBox_Extension_Pack-5.0.24-108355.vbox-extpack
dest: /tmp/Oracle_VM_VirtualBox_Extension_Pack-5.0.24-108355.vbox-extpack
- name: install extensions for virtual box using linux utility yes to respond to license agreement
become: yes
shell: "yes | VBoxManage extpack install --replace /tmp/Oracle_VM_VirtualBox_Extension_Pack-5.0.24-108355.vbox-extpack"
#Now PHP virtual box tasks
- name: install PHPvirtualbox packages
become: yes
apt:
pkg: "{{ item }}"
state: present
update_cache: yes
with_items: "{{ PHPpackages }}"
- name: remove phpvirtualbox folder in case it exists and files and folders are inside
become: yes
file:
path: /var/www/html/phpvirtualbox
state: absent
- name: create directory for phpVirtualBox to be unzipped to
become: yes
file:
path: /var/www/html/phpvirtualbox
state: directory
mode: 0777
- name: unzip phpvirtualbox
become: yes
unarchive:
src: https://sourceforge.net/projects/phpvirtualbox/files/phpvirtualbox-5.0-5.zip
dest: /var/www/html/
mode: 0777
remote_src: yes
# COPY module did not work and could not find the file even though it was there.
# This should still be idempotent b/c i make sure it is a clean unzip/install/move of phpvirtualbox directory
- name: Move data out of phpvirtualbox-5.0-5 folder into phpvirtualbox dir
become: yes
shell: "mv /var/www/html/phpvirtualbox-5.0-5/* /var/www/html/phpvirtualbox && rm -r /var/www/html/phpvirtualbox-5.0-5/"
- name: chmod the new directory just in case
become: yes
file:
path: /var/www/html/phpvirtualbox
mode: 0777
# COPY module did not work and could not find the file even though it was there.
# This should still be idempotent b/c i make sure it is a clean unzip/install/move of phpvirtualbox directory
- name: copy config file using shell b/c
become: yes
shell: "cp /var/www/html/phpvirtualbox/config.php-example /var/www/html/phpvirtualbox/config.php"
# - name: change user in config file
# become: yes
# lineinfile:
# path: /var/www/html/phpvirtualbox/config.php
# regexp: '^var \$username = '
# line: "var $username = 'vbuser';"
- name: change user in config file
become: yes
lineinfile:
path: /var/www/html/phpvirtualbox/config.php
regexp: '^var \$username = '
line: "var $username = 'ubuntu';"
- name: change password in config file
become: yes
lineinfile:
path: /var/www/html/phpvirtualbox/config.php
regexp: '^var \$password = '
line: "var $password = 'pass';"
- name: Create a new file called virtualbox in etc/default
become: yes
file:
path: /etc/default/virtualbox
state: touch
# - name: add line to the newly created file
# become: yes
# lineinfile:
# path: /etc/default/virtualbox
# line: "VBOXWEB_USER=vbuser"
- name: add line to the newly created file
become: yes
lineinfile:
path: /etc/default/virtualbox
regexp: '^VBOXWEB_USER='
line: "VBOXWEB_USER=ubuntu"
- name: restart vboxweb service
become: yes
systemd:
name: vboxweb-service
state: restarted
- name: restart vboxdrv service
become: yes
systemd:
name: vboxdrv
state: restarted
- name: restart apache2 service
become: yes
systemd:
name: apache2
state: restarted
- name: install vagrant
become: yes
apt:
name: vagrant
state: present
# - name: get 32 bit box
# become: yes
# get_url:
# url: http://files.vagrantup.com/precise32.box
# dest: "{{ box_file }}"