Skip to content

Commit fc6c1cb

Browse files
committed
Automatic Emissions-API Software Setup
This patch adds a playbook to setup the software from https://github.com/emissions-api/emissions-api.git It is running with gunicorn and is started and enabled via a service file. Also the software is running as the user emissions-api with less priviledges. Closes #15. The user emissions-api does own all software specific files, so this is also preparation for #5 Related to #16
1 parent 3756a1b commit fc6c1cb

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

emissions-api.yml

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
3+
- hosts: server
4+
become: yes
5+
vars_files:
6+
- secret-vars.yml
7+
tasks:
8+
- name: install needed software
9+
become: yes
10+
apt:
11+
name:
12+
- git
13+
- python3
14+
- python3-gdal
15+
- python3-psycopg2
16+
- python3-pycurl
17+
- python3-numpy
18+
- python3-venv
19+
- python3-wheel
20+
21+
- name: create Emissions-API user
22+
user:
23+
name: emissions-api
24+
system: yes
25+
home: /opt/emissions-api
26+
27+
- name: create data directory
28+
file:
29+
path: /opt/emissions-api/data/
30+
owner: emissions-api
31+
group: emissions-api
32+
state: directory
33+
34+
- name: create python environment
35+
command: python3 -m venv --system-site-packages /opt/emissions-api/env
36+
args:
37+
creates: /opt/emissions-api/env
38+
39+
- name: clone Emissions-API repository
40+
command: git clone https://github.com/emissions-api/emissions-api.git /opt/emissions-api/emissions-api
41+
args:
42+
creates: /opt/emissions-api/emissions-api
43+
44+
- name: install Emissions-API requirements
45+
command: /opt/emissions-api/env/bin/pip install -r /opt/emissions-api/emissions-api/requirements.txt
46+
47+
- name: install gunicorn
48+
command: /opt/emissions-api/env/bin/pip install gunicorn
49+
50+
- name: install Emissions-API config file
51+
copy:
52+
content: |
53+
database: postgresql://emissionsapi:{{ database_emissionsapi_password }}@127.0.0.1/emissionsapi
54+
storage: /opt/emissionsapi/data
55+
download:
56+
date:
57+
begin: '2019-02-1T00:00:00.000Z'
58+
end: '2019-03-01T00:00:00.000Z'
59+
country:
60+
dest: /opt/emissions-api/emissions-api.yml
61+
force: yes
62+
owner: emissions-api
63+
group: emissions-api
64+
mode: 0600
65+
66+
- name: ensure correct ownership
67+
file:
68+
owner: emissions-api
69+
group: emissions-api
70+
recurse: yes
71+
path: /opt/emissions-api
72+
73+
- name: install Emissions-API service file
74+
copy:
75+
dest: /lib/systemd/system/emissionsapi-web.service
76+
content: |
77+
[Unit]
78+
Description=Emissions API Web Service
79+
80+
[Service]
81+
ExecStart=/opt/emissions-api/env/bin/gunicorn --workers 4 emissionsapi.web:app
82+
WorkingDirectory=/opt/emissions-api/emissions-api/
83+
User=emissions-api
84+
RestartSec=5
85+
Restart=always
86+
87+
[Install]
88+
WantedBy=multi-user.target
89+
force: yes
90+
notify:
91+
- reload systemd
92+
- restart emissionsapi-web
93+
94+
- name: run Emissions-API now and on boot
95+
service:
96+
name: emissionsapi-web
97+
enabled: yes
98+
state: started
99+
100+
handlers:
101+
- name: reload systemd
102+
systemd:
103+
daemon_reload: yes
104+
105+
- name: restart emissionsapi-web
106+
service:
107+
name: emissionsapi-web
108+
state: restarted

secret-vars.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
$ANSIBLE_VAULT;1.1;AES256
2+
32313166363835386539323866656231343733326632616239623230353339623338326664643035
3+
6236633337653733303233326332333862626261353834310a326130303737313130363838356662
4+
64303836373534616366363962383034373233666436376630653165666336633830613737386439
5+
3263303863633532620a326435333133633137343733373234663837663330353365353664663461
6+
64656135383631666533373935336562373437313539333435343463376463323061306561656634
7+
30366366643037346434666261653935613739653465633433306635656237366232326566366435
8+
65653263636263373933393431623162333466316635393536333332323033623461333537386461
9+
36373766666630653831383662333338383835313839303439653131353463323431643639383063
10+
30666664363833616138363261656135626132323835633439393330323038646134333630613461
11+
3231356635343339396539633530363139333861363737643332

0 commit comments

Comments
 (0)