-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaybook.yml
More file actions
154 lines (137 loc) · 4.71 KB
/
playbook.yml
File metadata and controls
154 lines (137 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
---
- hosts: all
connection: ssh
become: yes
any_errors_fatal: True
gather_facts: False
tasks:
# - name: updating the system
# shell: sudo apt update
# - name: update the server keys
# shell: sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8C47BE8E75BCA694
- name: Create file
copy:
content: Create \n
dest: /tmp/test.txt
# - name: Install dependancies
# apt: name={{ item }} state=installed
# with_items:
# - python-setuptools
# - python-dev
# - build-essential
# - python-pip
# - python3.6
# - python3-pip
# - python3-venv
- name: updating pip3
shell: sudo pip install --upgrade pip
- name: installing virtual env
shell: sudo pip3 install virtualenv
- name: making virtual env
shell: python3 -m venv venv
- name: activate virtual environment
shell: . venv/bin/activate
# - name: Free port 80
# command: fuser -k 80/tcp
# become: yes
- name: ensure nginx is at the latest version
apt: name=nginx state=latest
- name: start nginx
service:
name: nginx
state: started
- name: Create directory Remote
file:
state: directory
path: Remote
- name: Make server known host
command: ssh-keyscan 35.193.71.38 >> ~/.ssh/known_hosts
- name: Pull project from github
git:
accept_hostkey: yes
repo: "https://github.com/joseph-njogu/bitcotrade.git"
dest: Remote/
update: yes
force: no
clone: yes
- name: installing requirements
pip:
requirements: /home/elephant/Remote/requirements.txt
virtualenv: /home/elephant/venv
virtualenv_python: python3.6
- name: Makemigrations
shell: |
. /home/elephant/venv/bin/activate
python3 /home/elephant/Remote/Cryptotrade/manage.py migrate
# - name: Collect static files
# shell: |
# . /home/elephant/venv/bin/activate
# python3 /home/elephant/Remote/Cryptotrade/manage.py collectstatic
- name: Recursively change ownership of a directory
file:
path: /home/elephant/Remote/Cryptotrade
state: directory
recurse: yes
owner: elephant
- name: start gunicorn
shell: |
. /home/elephant/venv/bin/activate
cd /home/elephant/Remote/Cryptotrade
gunicorn --daemon --workers 3 --bind unix:/home/elephant/Remote/Cryptotrade/Cryptotrade.sock Cryptotrade.wsgi
# shell: gunicorn --daemon --workers 3 --bind unix:/home/elephant/Remote/locallib/locallib.sock locallib.wsgi
- name: copy the nginx config file
copy:
src: .circleci/bitcotrade
dest: /etc/nginx/sites-available/
become: yes
- name: create symlink
file:
src: /etc/nginx/sites-available/bitcotrade
dest: /etc/nginx/sites-enabled/default
state: link
become: yes
- name: restart nginx
service:
name: nginx
state: restarted
become: yes
- name: stopping
service:
name: nginx
state: stopped
become: yes
- name: add repository for certbot
apt_repository:
repo: deb http://ppa.launchpad.net/certbot/certbot/ubuntu bionic main
state: present
# when: ansible_distribution_release == 'bionic'
- name: Install base packages
apt:
name: "{{ packages }}"
vars:
packages:
- python-certbot-nginx
- name: Enable UFW
ufw:
state: enabled
- name: Allow OpenSSH
ufw:
rule: allow
name: OpenSSH
- name: Allow Nginx Full
ufw:
rule: allow
name: Nginx Full
- name: Obtain SSL certificate
shell: certbot --nginx --noninteractive --agree-tos --email josephnjogu487@gmail.com -d blacktoolz.duckdns.org -d www.blacktoolz.duckdns.org
become: yes
- name: Free port 80
command: fuser -k 80/tcp
become: yes
# - name: Generate Certificate for Domains
# shell: certbot-auto --authenticator standalone --installer nginx -d josephdevs.duckdns.org -d www.josephdevs.duckdns.org -d --email josephnjogu487@gmail.com --agree-tos -n --no-verify-ssl --pre-hook "sudo systemctl stop nginx" --post-hook "sudo systemctl start nginx" --redirect
- name: restart nginx
service:
name: nginx
state: stopped
become: yes