Skip to content

Commit dd1b9ab

Browse files
authored
VAGRANT: Fix Ubuntu Development VMs (#6909)
* GITIGNORE: Add vagrant log and ansible retry files This patch adds the following to the project's .gitignore file: - Vagrant's log file - Ansible's retry files Signed-off-by: Mark Stenglein <[email protected]> * ANSIBLE: Add Ubuntu Ansible playbook for dev env This patch adds an Ansible playbook to provision an Ubuntu based development environment. This playbook is fully idempotent and can be run multiple times without negative consequences. Signed-off-by: Mark Stenglein <[email protected]> * VAGRANTFILE: Clean Vagrantfile There was a lot of extra VMs being provisioned by the existing Vagrantfile. Some of this may need to come back but I am removing it with this commit to demonstrate that this is all that is needed. Signed-off-by: Mark Stenglein <[email protected]> * ANSIBLE: UBUNTU: PLAYBOOK: Add .env configuration I missed the configuration of the .env file in the initial commit. This patch adds these configuration steps as well as the needed Cron job for the Artisan scheduler. Signed-off-by: Mark Stenglein <[email protected]> * Revert "VAGRANTFILE: Clean Vagrantfile" This reverts commit a608a30. * VAGRANTFILE: Fix Ubuntu Vagrant Development Boxes This patch addresses problems with the existing Vagrant deployment configurations for the Ubuntu VMs. - The vagrant file is configuring the VMs for an incorrect bridge interface. Fixed by changing the config to use the default networking as well as a port-forward. - Moves provisioning over to the Ansible-Local playbook I wrote. Signed-off-by: Mark Stenglein <[email protected]>
1 parent f01c93e commit dd1b9ab

File tree

4 files changed

+256
-9
lines changed

4 files changed

+256
-9
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ tests/_support/_generated/*
5252
*.cache
5353

5454
.vagrant
55+
*.log
56+
*.retry
5557

5658
\.php_cs\.dist
5759

Vagrantfile

+18-9
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,34 @@ Vagrant.configure("2") do |config|
88
config.vm.define "bionic" do |bionic|
99
bionic.vm.box = "ubuntu/bionic64"
1010
bionic.vm.hostname = 'bionic'
11-
bionic.vm.network "public_network", bridge: NETWORK_BRIDGE
12-
bionic.vm.provision :shell, :inline => "wget #{SNIPEIT_SH_URL}"
13-
bionic.vm.provision :shell, :inline => "chmod 755 snipeit.sh"
11+
bionic.vm.network "forwarded_port", guest: 80, host: 8080
12+
bionic.vm.synced_folder ".", "/vagrant", :owner => 'www-data',
13+
:group => 'vagrant', :mount_options => ['dmode=775', 'fmode=775']
14+
bionic.vm.provision "ansible_local" do |ansible|
15+
ansible.playbook = "ansible/ubuntu/vagrant_playbook.yml"
16+
end
1417
end
1518

1619
config.vm.define "xenial" do |xenial|
1720
xenial.vm.box = "ubuntu/xenial64"
1821
xenial.vm.hostname = 'xenial'
19-
xenial.vm.network "public_network", bridge: NETWORK_BRIDGE
20-
xenial.vm.provision :shell, :inline => "wget #{SNIPEIT_SH_URL}"
21-
xenial.vm.provision :shell, :inline => "chmod 755 snipeit.sh"
22+
xenial.vm.network "forwarded_port", guest: 80, host: 8080
23+
xenial.vm.synced_folder ".", "/vagrant", :owner => 'www-data',
24+
:group => 'vagrant', :mount_options => ['dmode=775', 'fmode=775']
25+
xenial.vm.provision "ansible_local" do |ansible|
26+
ansible.playbook = "ansible/ubuntu/vagrant_playbook.yml"
27+
end
2228
end
2329

2430
config.vm.define "trusty" do |trusty|
2531
trusty.vm.box = "ubuntu/trusty32"
2632
trusty.vm.hostname = 'trusty'
27-
trusty.vm.network "public_network", bridge: NETWORK_BRIDGE
28-
trusty.vm.provision :shell, :inline => "wget #{SNIPEIT_SH_URL}"
29-
trusty.vm.provision :shell, :inline => "chmod 755 snipeit.sh"
33+
trusty.vm.network "forwarded_port", guest: 80, host: 8080
34+
trusty.vm.synced_folder ".", "/vagrant", :owner => 'www-data',
35+
:group => 'vagrant', :mount_options => ['dmode=775', 'fmode=775']
36+
trusty.vm.provision "ansible_local" do |ansible|
37+
ansible.playbook = "ansible/ubuntu/vagrant_playbook.yml"
38+
end
3039
end
3140

3241
config.vm.define "centos7" do |centos7|
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<VirtualHost *:80>
2+
<Directory {{ app_path }}/public>
3+
Allow From All
4+
AllowOverride All
5+
Options -Indexes
6+
</Directory>
7+
8+
DocumentRoot {{ app_path }}/public
9+
ServerName {{ fqdn }}
10+
</VirtualHost>

ansible/ubuntu/vagrant_playbook.yml

+226
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
---
2+
- name: Set up local server
3+
hosts: all
4+
remote_user: vagrant
5+
become_user: root
6+
become_method: sudo
7+
vars:
8+
app_path: "/var/www/snipeit"
9+
fqdn: "localhost"
10+
tasks:
11+
- name: Update and upgrade existing apt packages
12+
become: true
13+
apt:
14+
upgrade: yes
15+
update_cache: yes
16+
- name: Install Utilities
17+
become: true
18+
apt:
19+
name: "{{ packages }}"
20+
state: present
21+
vars:
22+
packages:
23+
- nano
24+
- vim
25+
- name: Installing Apache httpd, PHP, MariaDB and other requirements.
26+
become: true
27+
apt:
28+
name: "{{ packages }}"
29+
state: present
30+
vars:
31+
packages:
32+
- mariadb-client
33+
- php
34+
- php-curl
35+
- php-mysql
36+
- php-gd
37+
- php-ldap
38+
- php-zip
39+
- php-mbstring
40+
- php-xml
41+
- php-bcmath
42+
- curl
43+
- git
44+
- unzip
45+
- python-pymysql
46+
#
47+
# Install the lastest version of composer
48+
#
49+
- name: Composer check
50+
stat:
51+
path: /usr/local/bin/composer
52+
register: composer_exits
53+
- name: Install Composer
54+
shell: |
55+
EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig)
56+
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
57+
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
58+
59+
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
60+
then
61+
>&2 echo 'ERROR: Invalid installer signature'
62+
rm composer-setup.php
63+
exit 1
64+
fi
65+
66+
php composer-setup.php --quiet
67+
RESULT=$?
68+
rm composer-setup.php
69+
mv composer.phar /usr/local/bin/composer
70+
exit $RESULT
71+
when: not composer_exits.stat.exists
72+
args:
73+
creates: /usr/local/bin/composer
74+
become: true
75+
#
76+
# Install and Configure MariaDB
77+
#
78+
- name: Install MariaDB
79+
become: true
80+
apt:
81+
name: mariadb-server
82+
state: present
83+
register: sql_server
84+
- name: Start and Enable MySQL server
85+
become: true
86+
systemd:
87+
state: started
88+
enabled: yes
89+
name: mariadb
90+
- name: Create Vagrant mysql password
91+
become: true
92+
mysql_user:
93+
name: vagrant
94+
password: vagrant
95+
login_unix_socket: /var/run/mysqld/mysqld.sock
96+
priv: "*.*:ALL"
97+
state: present
98+
- name: Enable remote mysql
99+
replace:
100+
path: /etc/mysql/mariadb.conf.d/50-server.cnf
101+
regexp: "127.0.0.1"
102+
replace: "0.0.0.0"
103+
become: true
104+
notify:
105+
- restart mysql
106+
- name: Create snipeit database
107+
become: true
108+
mysql_db:
109+
name: snipeit
110+
state: present
111+
login_unix_socket: /var/run/mysqld/mysqld.sock
112+
#
113+
# Install Apache Web Server
114+
#
115+
- name: Install Apache 2.4
116+
apt:
117+
name: "{{ packages }}"
118+
state: present
119+
vars:
120+
packages:
121+
- apache2
122+
- libapache2-mod-php
123+
become: true
124+
register: apache2_server
125+
- name: Start and Enable Apache2 Server
126+
become: true
127+
systemd:
128+
name: apache2
129+
state: started
130+
enabled: yes
131+
#- name: Disable Apache modules
132+
# become: true
133+
# apache2_module:
134+
# state: absent
135+
# name: "{{ item }}"
136+
# with_items:
137+
# #- mpm_prefork
138+
# notify:
139+
# - restart apache2
140+
- name: Enable Apache modules
141+
become: true
142+
apache2_module:
143+
state: present
144+
name: "{{ item }}"
145+
with_items:
146+
- rewrite
147+
- vhost_alias
148+
- deflate
149+
- expires
150+
- proxy_fcgi
151+
- proxy
152+
notify:
153+
- restart apache2
154+
- name: Install Apache VirtualHost File
155+
become: true
156+
template:
157+
src: apachevirtualhost.conf.j2
158+
dest: "/etc/apache2/sites-available/snipeit.conf"
159+
- name: Enable VirtualHost
160+
become: true
161+
command: a2ensite snipeit
162+
args:
163+
creates: /etc/apache2/sites-enabled/snipeit.conf
164+
notify:
165+
- restart apache2
166+
- name: Map apache dir to local folder
167+
become: true
168+
file:
169+
src: /vagrant
170+
dest: "{{ app_path }}"
171+
state: link
172+
notify:
173+
- restart apache2
174+
#
175+
# Install dependencies from composer
176+
#
177+
- name: Install dependencies from composer
178+
composer:
179+
command: install
180+
working_dir: "{{ app_path }}"
181+
notify:
182+
- restart apache2
183+
#
184+
# Configure .env file
185+
#
186+
- name: Copy .env file
187+
copy:
188+
src: "{{ app_path }}/.env.example"
189+
dest: "{{ app_path }}/.env"
190+
- name: Configure .env file
191+
lineinfile:
192+
path: "{{ app_path }}/.env"
193+
regexp: "{{ item.regexp }}"
194+
line: "{{ item.line }}"
195+
with_items:
196+
- { regexp: '^DB_HOST=', line: 'DB_HOST=127.0.0.1'}
197+
- { regexp: '^DB_DATABASE=', line: 'DB_DATABASE=snipeit' }
198+
- { regexp: '^DB_USERNAME=', line: 'DB_USERNAME=vagrant' }
199+
- { regexp: '^DB_PASSWORD=', line: 'DB_PASSWORD=vagrant' }
200+
- { regexp: '^APP_URL=', line: "APP_URL=http://{{ fqdn }}" }
201+
- { regexp: '^APP_ENV=', line: "APP_ENV=development" }
202+
- { regexp: '^APP_DEBUG=', line: "APP_ENV=true" }
203+
- name: Generate application key
204+
shell: "php {{ app_path }}/artisan key:generate --force"
205+
- name: Artisan Migrate
206+
shell: "php {{ app_path }}/artisan migrate --force"
207+
#
208+
# Create Cron Job
209+
#
210+
- name: Create scheduler cron job
211+
become: true
212+
cron:
213+
name: "Snipe-IT Artisan Scheduler"
214+
job: "/usr/bin/php {{ app_path }}/artisan schedule:run"
215+
handlers:
216+
- name: restart apache2
217+
become: true
218+
systemd:
219+
name: apache2
220+
state: restarted
221+
- name: restart mysql
222+
become: true
223+
systemd:
224+
name: mysql
225+
state: restarted
226+

0 commit comments

Comments
 (0)