-
Notifications
You must be signed in to change notification settings - Fork 1
WIP: Vagrant with provision #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,5 @@ | |
###< symfony/web-server-bundle ### | ||
|
||
config/parameters.yaml | ||
|
||
.vagrant |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
- hosts: all | ||
roles: | ||
- role: app | ||
become: true | ||
- role: php72 | ||
become: true | ||
- role: npm | ||
become: true | ||
- role: composer | ||
become: true | ||
- role: nginx | ||
become: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
app_hostname: bcr.www | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
dependencies: | ||
- nginx | ||
- php72 |
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 |
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$ { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
- name: Install compopser package | ||
apt: | ||
name: composer | ||
state: present |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
- name: restart nginx | ||
become: true | ||
service: | ||
name: nginx | ||
state: restarted |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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 - | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't bionic's default node version already 8? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wait what?? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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 |
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 |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
apt-get -y install python | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got problems with provisioning without this pre-installation |
There was a problem hiding this comment.
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 meThere was a problem hiding this comment.
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