Skip to content

Commit 6cfab6b

Browse files
committed
Transfer ansible playbooks to roles, closes #30
1 parent f8cf7f6 commit 6cfab6b

File tree

22 files changed

+65
-35
lines changed

22 files changed

+65
-35
lines changed

Vagrantfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Vagrant.configure(2) do |config|
1010
# See https://github.com/mitchellh/vagrant/issues/5005
1111
config.ssh.insert_key = false
1212

13-
config.vm.provision "ansible" do |ansible|
13+
# Run Ansible from the Vagrant VM
14+
config.vm.provision "ansible_local" do |ansible|
1415
ansible.verbose = "vv"
1516
ansible.playbook = "playbooks/vagrant.yml"
1617
end

playbooks/tasks/base.yml renamed to playbooks/roles/base/tasks/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
with_items:
44
- curl
55
- git
6-
- python-mysqldb
6+
- python-mysqldb
7+
- zip
8+
- unzip
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
dependencies:
3+
- { role: base }
4+
- { role: mysql }
5+
- { role: php-fpm }
6+
- { role: nginx }

playbooks/tasks/laravel-quickstart.yml renamed to playbooks/roles/laravel-quickstart/tasks/main.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,41 @@
99
git: repo=https://github.com/laravel/quickstart-basic
1010
dest=/vagrant/laravel-quickstart
1111
update=no
12+
become: true
13+
become_user: "{{ www_user }}"
1214

1315
- name: Copy across new .env file
1416
template:
15-
src=laravel/.env.j2
17+
src=.env.j2
1618
dest=/vagrant/laravel-quickstart/.env
17-
18-
- stat: path=/vagrant/laravel-quickstart/vendor
19-
register: p
19+
become: true
20+
become_user: "{{ www_user }}"
2021

2122
- name: Install Laravel project dependencies
22-
shell: cd /vagrant/laravel-quickstart && composer install
23-
when: p.stat.isdir is not defined
23+
shell: cd /vagrant/laravel-quickstart && COMPOSER_PROCESS_TIMEOUT=900 composer install
24+
become: true
25+
become_user: "{{ www_user }}"
2426

2527
- name: Generate laravel key
2628
shell: cd /vagrant/laravel-quickstart && php artisan key:generate
29+
become: true
30+
become_user: "{{ www_user }}"
2731

2832
- name: Execute migrations for the quickstart example
2933
shell: cd /vagrant/laravel-quickstart && php artisan migrate
34+
become: true
35+
become_user: "{{ www_user }}"
3036

3137
- name: Copy across new php-fpm pool config for laravel
3238
template:
33-
src=php-fpm/laravel.conf.j2
39+
src=php-fpm.conf.j2
3440
dest=/etc/php/5.6/fpm/pool.d/laravel.conf
3541
notify:
3642
- restart php-fpm
3743

3844
- name: Copy across new virtual host for laravel
3945
template:
40-
src=nginx/laravel.conf.j2
46+
src=nginx.conf.j2
4147
dest=/etc/nginx/sites-available/laravel.conf
4248
notify:
4349
- restart nginx
File renamed without changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- name: restart nginx
2+
service: name=nginx state=restarted

playbooks/tasks/nginx.yml renamed to playbooks/roles/nginx/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
- name: Copy across new nginx config
66
template:
7-
src=nginx/nginx.conf.j2
7+
src=nginx.conf.j2
88
dest=/etc/nginx/nginx.conf
99
notify:
1010
- restart nginx
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- name: restart php-fpm
2+
service: name=php5.6-fpm state=restarted

playbooks/roles/php-fpm/meta/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
dependencies:
3+
- { role: php }
File renamed without changes.

playbooks/tasks/php.yml renamed to playbooks/roles/php/tasks/main.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@
1515
- php5.6-intl
1616
- php5.6-cli
1717
- php5.6-mcrypt
18+
- php5.6-mbstring
19+
- php5.6-dom
1820

1921
- name: Enable the MCrypt extension
2022
shell: phpenmod mcrypt
2123

2224
- name: Install composer
23-
shell: curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
25+
shell: curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
26+
27+
- name: Configure composer cache directory to avoid using slow NFS
28+
shell: composer config --global cache-dir /dev/shm/composer/cache
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
dependencies:
3+
- { role: base }
4+
- { role: mysql }
5+
- { role: php-fpm }
6+
- { role: nginx }

playbooks/tasks/symfony-standard.yml renamed to playbooks/roles/symfony-standard/tasks/main.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,31 @@
99
git: repo=https://github.com/symfony/symfony-standard.git
1010
dest=/vagrant/symfony-standard
1111
update=no
12+
become: true
13+
become_user: "{{ www_user }}"
1214

1315
- name: Copy across new parameters.yml
1416
template:
15-
src=symfony/symfony_parameters.yml.j2
17+
src=parameters.yml.j2
1618
dest=/vagrant/symfony-standard/app/config/parameters.yml
17-
18-
- stat: path=/vagrant/symfony-standard/vendor
19-
register: p
19+
become: true
20+
become_user: "{{ www_user }}"
2021

2122
- name: Install Symfony2 project dependencies
22-
shell: cd /vagrant/symfony-standard && composer install
23-
when: p.stat.isdir is not defined
23+
shell: cd /vagrant/symfony-standard && COMPOSER_PROCESS_TIMEOUT=900 composer install
24+
become: true
25+
become_user: "{{ www_user }}"
2426

2527
- name: Copy across new php-fpm pool config for symfony
2628
template:
27-
src=php-fpm/symfony.conf.j2
29+
src=php-fpm.conf.j2
2830
dest=/etc/php/5.6/fpm/pool.d/symfony.conf
2931
notify:
3032
- restart php-fpm
3133

3234
- name: Copy across new virtual host for symfony
3335
template:
34-
src=nginx/symfony.conf.j2
36+
src=nginx.conf.j2
3537
dest=/etc/nginx/sites-available/symfony.conf
3638
notify:
3739
- restart nginx

playbooks/vagrant.yml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@
55
document_root: /vagrant
66
www_user: vagrant
77
www_group: vagrant
8-
handlers:
9-
- name: restart nginx
10-
service: name=nginx state=restarted
11-
- name: restart php-fpm
12-
service: name=php5.6-fpm state=restarted
138
pre_tasks:
149
- name: update apt cache
15-
apt: update_cache=yes
16-
tasks:
17-
- include: tasks/base.yml
18-
- include: tasks/nginx.yml
19-
- include: tasks/mysql.yml
20-
- include: tasks/php.yml
21-
- include: tasks/php-devtools.yml
22-
- include: tasks/php-fpm.yml
23-
- include: tasks/symfony-standard.yml
24-
- include: tasks/laravel-quickstart.yml
10+
apt: update_cache=yes cache_valid_time=3600
11+
roles:
12+
- base
13+
- nginx
14+
- mysql
15+
- php
16+
- php-devtools
17+
- php-fpm
18+
- symfony-standard
19+
- laravel-quickstart

0 commit comments

Comments
 (0)