Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
###< symfony/web-server-bundle ###

config/parameters.yaml

.vagrant
24 changes: 24 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Vagrant.configure('2') do |config|
config.vm.box = 'ubuntu/bionic64'
config.vm.host_name = 'bcr.www'
config.ssh.forward_agent = true

config.vm.network 'private_network', ip: '192.168.123.12'
config.vm.network 'forwarded_port', guest: 80, host: 9050

config.vm.synced_folder ".", "/var/www", :nfs => true

config.vm.provision :shell, path: "bootstrap.sh"

config.vm.provision "shell" do |s|
ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip
s.inline = <<-SHELL
echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
echo #{ssh_pub_key} >> /root/.ssh/authorized_keys
SHELL
end

config.vm.provision :ansible do |ansible|
ansible.playbook = "ansible/main.yml"
end
end
1 change: 1 addition & 0 deletions ansible/main.retry
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default
13 changes: 13 additions & 0 deletions ansible/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- hosts: all
roles:
- role: app
become: true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity: why the become on role level? Most of the time I have mixed permission requirements per role for the different tasks, therefore always set this on a task level, blindly executing everything with root sounds a bit risky to me

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my way for it. Set it to the roles not global. But i think this could be cleaned up for this special box

- role: php72
become: true
- role: npm
become: true
- role: composer
become: true
- role: nginx
become: true
3 changes: 3 additions & 0 deletions ansible/roles/app/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
app_hostname: bcr.www

4 changes: 4 additions & 0 deletions ansible/roles/app/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
dependencies:
- nginx
- php72
25 changes: 25 additions & 0 deletions ansible/roles/app/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
- name: ensure hosts entry
lineinfile:
dest: /etc/hosts
regexp: '^127.0.0.1'
line: '127.0.0.1 localhost {{ app_hostname }}'

- name: nginx config copy
template:
src: vhost.j2
dest: /etc/nginx/sites-available/bcr.conf

- name: nginx config API link
file:
src: /etc/nginx/sites-available/bcr.conf
dest: /etc/nginx/sites-enabled/bcr.conf
state: link

- name: Remove symlink
file:
path: /etc/nginx/sites-enabled/default
state: absent
notify:
- restart nginx
- restart php-fpm
23 changes: 23 additions & 0 deletions ansible/roles/app/templates/vhost.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# nginx
server {
listen 80;
listen [::]:80 ipv6only=on;

root /var/www/public;
index index.php index.html index.htm;

server_name {{ app_hostname }};

location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}

location ~ \.php$ {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this pattern could be more restrictive, there is only one dispatcher file that needs to be accessible by php-fpm

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right :D copy paste, thx for eagle eyes

try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
5 changes: 5 additions & 0 deletions ansible/roles/composer/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: Install compopser package
apt:
name: composer
state: present
6 changes: 6 additions & 0 deletions ansible/roles/nginx/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: restart nginx
become: true
service:
name: nginx
state: restarted
16 changes: 16 additions & 0 deletions ansible/roles/nginx/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: Install nginx packages.
apt:
name: nginx
state: present

- name: Uninstall apache packages.
apt:
name: httpd
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since when is this called httpd in Debian/Ubuntu? sure this is not supposed to be apache

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jipp, it could removed in this ubuntu version. Got problems with older boxes

state: absent

- name: start and enable nginx service.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really needed? apt automatically starts the service normally or is this purely for the case that apache had previously blocked the port when nginx was installed? in that case, removing apache before nginx would suffice also without this additional step

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its to get shure that nginx will be restarted when adding my configuration for it, after copy processes I restart it

service:
name: nginx
state: started
enabled: true
18 changes: 18 additions & 0 deletions ansible/roles/npm/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- name: install node sources
shell: curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't bionic's default node version already 8?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its better to set the Version because of further updates


- name: install nodejs
apt:
name: nodejs
state: present

- name: install npm
apt:
name: npm
state: present

- name: install yarn
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the recommended way of installing yarn right now? I thought their apt repo would be the better choice?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jay :D its not the best way, i´ll have a look for it

npm:
name: yarn
global: true
10 changes: 10 additions & 0 deletions ansible/roles/php72/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
fpm_user: www-data
fpm_group: www-data
fpm_listen: 127.0.0.1:9000
fpm_log_path: /var/log/php

php_ini:
'date.timezone': "Europe/Berlin"
'memory_limit': 2048M
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait what??

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My defaults for projects ;) could remove it, if not needed

'max_execution_time': 300
6 changes: 6 additions & 0 deletions ansible/roles/php72/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: restart php-fpm
become: true
service:
name: php7.2-fpm
state: restarted
32 changes: 32 additions & 0 deletions ansible/roles/php72/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
- name: add php7.2 repository
apt_repository:
repo: 'ppa:ondrej/php'
state: present

- name: Install php packages.
apt:
name: ['memcached', 'php7.2', 'php7.2-cli', 'php7.2-fpm', 'php7.2-json', 'php7.2-dom', 'php7.2-memcached', 'php7.2-curl', 'curl']
state: present
notify:
- restart php-fpm

- name: ensure php log dir exists
file:
path: "{{ fpm_log_path }}"
state: directory
owner: "{{ fpm_user }}"
group: "{{ fpm_group }}"
recurse: true

- name: place php-fpm configuration file.
template:
src: fpm-www.conf.j2
dest: /etc/php/7.2/fpm/pool.d/www.conf
notify:
- restart php-fpm

- name: start and enable php-fpm service.
service:
name: php7.2-fpm
enabled: true
12 changes: 12 additions & 0 deletions ansible/roles/php72/templates/fpm-www.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[www]
user = {{ fpm_user }}
group = {{ fpm_group }}
listen = {{ fpm_listen }}
listen.allowed_clients = 127.0.0.1
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
3 changes: 3 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

apt-get -y install python
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really necessary? I thought python was installed by default in Debian and Ubuntu for ages, might be mistaken though.

Not a vagrant expert, might be stupid question: ansible is available automatically or is it executed by the host system and needs to be installed there?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got problems with provisioning without this pre-installation