|
| 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 |
0 commit comments