Skip to content

Commit 28a377e

Browse files
Ansible provision playbook
1 parent 84f635f commit 28a377e

File tree

10 files changed

+124
-0
lines changed

10 files changed

+124
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,7 @@ ENV/
9494

9595
# Ignore collected static files
9696
static
97+
98+
# Recomended ignore some files of ansible
99+
#contrib/ansible_playbooks/secret
100+

contrib/ansible_playbooks/Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
provision:
2+
@ansible-playbook provision.yml -v --ask-become-pass
3+
4+
deploy:
5+
@ansible-playbook deploy.yml --ask-become-pass
6+
7+
all:
8+
@ansible-playbook provision.yml deploy.yml --ask-become-pass
9+
10+
step:
11+
@ansible-playbook provision.yml deploy.yml --ask-become-pass --step
12+
13+
ping:
14+
@ansible all -i secret/hosts -m ping
15+
16+
install-ansible-local:
17+
@sudo apt-get install ansible sshpass
18+
19+
install-python-remote:
20+
@ansible all -i secret/hosts -m raw -a 'apt-get update && apt-get install -y python' -b --ask-sudo-pass

contrib/ansible_playbooks/ansible.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[defaults]
2+
hostfile = secret/hosts

contrib/ansible_playbooks/deploy.yml

Whitespace-only changes.
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
- hosts: virtualbox-vms
3+
vars_files:
4+
- secret/vars.yml
5+
become: true
6+
7+
tasks:
8+
- name: Authorize my key on remote host.
9+
authorized_key: user={{ management_user }} key={{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}
10+
become: yes
11+
12+
- name: Create user.
13+
user: name={{ project_name }} state=present
14+
15+
- name: Update system.
16+
apt: update_cache=yes
17+
18+
# - name: Upgrade system.
19+
# apt: upgrade=dist
20+
21+
- name: Install required system packages.
22+
apt: pkg={{ item }} state=installed update-cache=yes allow_unauthenticated=yes
23+
with_items: "{{ system_packages }}"
24+
25+
- name: Create ssh directory to root user.
26+
file: path=/root/.ssh state=directory owner=root group=root mode=0700
27+
28+
- name: Upload SSH key private root.
29+
copy: src={{ private_key_github }} dest=/root/.ssh/id_rsa mode=0400
30+
31+
- name: Upload SSH key public root.
32+
copy: src={{ public_key_github }} dest=/root/.ssh/id_rsa.pub mode=0644
33+
34+
- name: Pull sources from the repository.
35+
git: repo={{ project_repo }} dest={{ project_root }} version={{ branch }} accept_hostkey=True force=yes
36+
37+
- name: Change permissions.
38+
file: dest={{ project_home }} owner={{ project_name }} group={{ project_name }} recurse=yes
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[virtualbox-vms]
2+
vm01 ansible_port=22 ansible_ssh_host=<ip of your application host> environment_type=production branch=master ansible_ssh_pass=<your ssh password> ansible_ssh_user=<your ssh user>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#server {
2+
# listen 80;
3+
# server_name flasktutorial.abraseucodigo.com.br;
4+
# return 301 https://$server_name$request_uri;
5+
#}
6+
7+
server {
8+
listen 80;
9+
# server_name flasktutorial.abraseucodigo.com.br;
10+
11+
location / {
12+
client_max_body_size 5M;
13+
uwsgi_pass unix:///home/flasktutorial/uwsgi.sock;
14+
include uwsgi_params;
15+
}
16+
17+
location /static {
18+
autoindex on;
19+
alias /home/flasktutorial/project/staticfiles;
20+
}
21+
22+
location /robots.txt {
23+
alias /home/flasktutorial/project/robots.txt;
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
User-agent: *
2+
Disallow: /
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[program:uwsgi_flasktutorial]
2+
command=/home/flasktutorial/.venv/bin/uwsgi --master --socket=/home/flasktutorial/uwsgi.sock --chmod-socket=666 --workers=4 --pythonpath=/home/flasktutorial/project/ --wsgi=hci_api.wsgi --enable-threads --single-interpreter --stats /home/flasktutorial/uwsgistats.sock
3+
user=flasktutorial
4+
numprocs=1
5+
stdout_logfile=/home/flasktutorial/flasktutorial.log
6+
stderr_logfile=/home/flasktutorial/flasktutorial_error.log
7+
autostart=true
8+
autorestart=true
9+
stopsignal=QUIT
10+
environment=SECRET_KEY="<your secret key>",SERVER_NAME="<your host ip>",DATABASE_URI="sqlite:///tvseries.sqlite3"
11+
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
project_name: flasktutorial
3+
project_home: /home/flasktutorial
4+
project_root: /home/flasktutorial/project
5+
virtualenv_directory: /home/flasktutorial/.venv
6+
project_repo: [email protected]:rafaelhenrique/flask_tutorial.git
7+
private_key_github: /home/<your local user>/.ssh/id_rsa
8+
public_key_github: /home/<your local user>/.ssh/id_rsa.pub
9+
management_user: <management user of application host>
10+
production_variables:
11+
SECRET_KEY: '<inform your secret key>'
12+
SERVER_NAME: '<inform your host>'
13+
DATABASE_URI: 'sqlite:///tvseries.sqlite3'
14+
system_packages:
15+
- build-essential
16+
- python3
17+
- python3-dev
18+
- python3-venv
19+
- nginx
20+
- supervisor

0 commit comments

Comments
 (0)