Skip to content
Snippets Groups Projects
Commit e4731e3f authored by user's avatar user
Browse files

init

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 379 additions and 0 deletions
# ansible_PFR
Ce dépôt est constitué de playbook ansible permettant d'automatiser l'installation de l'application app_vapormap.
## initialisation
* Dans le fichier all.yaml situé dans le dossier group_vars, est présent les variables utilisées dans les playbooks, la modification de ces valeurs peut se faire pour l'adapter à votre environnement.
- hosts: all
gather_facts: no
become: true
roles:
- environment
- mariadb
- api
- frontend
---
- hosts: all
gather_facts: no
become: true
tasks:
- include_role:
name: frontend
tasks_from: destroy.yaml
- include_role:
name: api
tasks_from: destroy.yaml
- include_role:
name: mariadb
tasks_from: destroy.yaml
- include_role:
name: environment
tasks_from: destroy.yaml
\ No newline at end of file
---
database_vapormap: "db_vapormap"
use_vapormap: "user_vapormap"
password_vapormap: "vapormap"
vapormap_prod: "/home/app-vapormap/vapormap-prod"
vapormap_group: "app_vapormap"
vapormpap_dir: "/home/app-vapormap/vapormap-prod/app"
VAPORMAP_PATH: "/home/app-vapormap/vapormap-prod/venv/app/bin"
VAPOR_DBHOST: "localhost"
VAPORMAP_API_PORT: "8001"
VAPORMAP_URL_PORT: "8000"
VAPORMAP_URL_SERVERNAME: "0.0.0.0"
VAPORMAP_FRONTEND_ROOT: "home/app-vapormap/vapormap-prod/frontend/"
vapormap ansible_host=10.29.246.136 ansible_user=ubuntu ansible_ssh_private_key_file=/home/user/Téléchargements/demo.pem
vapormap ansible_host=10.29.246.136 ansible_user=ubuntu ansible_ssh_private_key_file=/home/user/Téléchargements/demo.pem
---
- name: initialisation de la base de données
command: bash /home/app-vapormap/vapormap-prod/flask.bash
listen: "flask"
remote_user: app-vapormap
- name: vapormap api
systemd:
name: vapormap-api.service
state: reloaded
listen: vapormap-api-service
remote_user: root
\ No newline at end of file
---
- name: Ensure vapormap-api.service is stopped
service:
name: vapormap-api.service
state: stopped
- name: Ensure vapormap-api.service service is deleted from systemd
file:
path: /etc/systemd/system/vapormap-api.service
state: absent
- name: Ensure dependent packages are removed
apt:
name: '{{ item }}'
state: absent
with_items:
- mariadb-client
- libmariadb-dev
- name: "supression de wheel"
pip:
name: wheel
virtualenv: /home/app-vapormap/vapormap-prod/venv/app
state: absent
remote_user: app-vapormap
become: yes
- name: "supression des requirements"
pip:
requirements: /home/app-vapormap/vapormap-prod/app/requirements/production.txt
virtualenv: /home/app-vapormap/vapormap-prod/venv/app
state: absent
remote_user: app-vapormap
become: yes
- name: Ensure flask.bash is deleted from systemd
file:
path: /home/app-vapormap/vapormap-prod/flask.bash
state: absent
vapormap ansible_host=10.29.246.136 ansible_user=ubuntu ansible_ssh_private_key_file=/home/user/Téléchargements/demo.pem
---
- name: "installation des dépendances python et librairies client mariadb"
apt:
name: "{{ item }}"
state: latest
loop:
- python3
- python3-pip
- python3-venv
- mariadb-client
- libmariadb-dev
- name: "installation de wheel"
pip:
name: wheel
virtualenv: /home/app-vapormap/vapormap-prod/venv/app
virtualenv_command: 'python3 -m venv'
remote_user: app-vapormap
become: yes
- name: "installation des requirements"
pip:
requirements: /home/app-vapormap/vapormap-prod/app/requirements/production.txt
virtualenv: /home/app-vapormap/vapormap-prod/venv/app
remote_user: app-vapormap
become: yes
- name: "script flask"
template:
src: templates/flask.bash.j2
dest: /home/app-vapormap/vapormap-prod/flask.bash
remote_user: app-vapormap
become: yes
notify: "flask"
- name: "vapormap api"
template:
src: templates/vapormap-api.service.j2
dest: /etc/systemd/system/vapormap-api.service
mode: '0755'
remote_user: app-vapormap
become: yes
notify: "vapormap-api-service"
#!/bin/bash
source /home/app-vapormap/vapormap-prod/venv/app/bin/activate
cd /home/app-vapormap/vapormap-prod/app/api
export VAPOR_DBNAME={{database_vapormap}}
export VAPOR_DBUSER={{use_vapormap}}
export VAPOR_DBPASS={{password_vapormap}}
export VAPOR_DBHOST=localhost
export FLASK_APP=app
export SETTINGS_FILE="production"
flask db upgrade
deactivate
[Unit]
Description=Gunicorn for VaporMap
After=network.target
[Service]
User={{use_vapormap}}
Group={{vapormap_group}}
WorkingDirectory={{vapormpap_dir}}
Environment="PATH={{VAPORMAP_PATH}}"
Environment="PYTHONPATH={{VAPORMAP_PATH}}"
Environment=PYTHONDONTWRITEBYTECODE=1
Environment=PYTHONUNBUFFERED=1
Environment=SETTINGS_FILE="production"
Environment=VAPOR_DBUSER={{use_vapormap}}
Environment=VAPOR_DBPASS={{password_vapormap}}
Environment=VAPOR_DBHOST={{VAPOR_DBHOST}}
Environment=VAPOR_DBNAME={{database_vapormap}}
ExecStart={{VAPORMAP_PATH}}/gunicorn wsgi:app --bind 0.0.0.0:{{VAPORMAP_API_PORT}}
[Install]
WantedBy=multi-user.target
\ No newline at end of file
---
- name: "uninstall de git"
apt:
name: git
state: latest
become: yes
- name: "création utilisateur app-vapormap"
user:
name: app-vapormap
state: absent
remove: yes
home: absent
\ No newline at end of file
vapormap ansible_host=10.29.246.136 ansible_user=ubuntu ansible_ssh_private_key_file=/home/user/Téléchargements/demo.pem
- name: "mise à jour du système"
apt:
update_cache: yes
become: yes
- name: "installation de git"
apt:
name: git
state: latest
become: yes
- name: "création utilisateur app-vapormap"
user:
name: app-vapormap
state: present
- name: "clônage du dépôt git"
git:
repo: https://gitlab.imt-atlantique.fr/vapormap/vapormap-app.git
dest: /home/app-vapormap/vapormap-prod
remote_user: app-vapormap
become: yes
---
- name: reload nginx
systemd:
name: nginx
state: reloaded
listen: reload_nginx
remote_user: root
\ No newline at end of file
---
- name: Ensure Nginx is stopped
service:
name: nginx
state: stopped
- name: Ensure Nginx service is deleted from systemd
file:
path: /etc/systemd/system/nginx.service
state: absent
- name: Ensure Nginx user is deleted
user:
name: nginx
state: absent
- name: Ensure Nginx group is deleted
group:
name: nginx
state: absent
- name: Ensure Nginx log directory is deleted
file:
path: '/var/log/nginx'
state: absent
- name: Ensure Nginx config directory is deleted
file:
path: '/etc/nginx'
state: absent
- name: Ensure Nginx binaries are deleted
file:
path: '/usr/sbin/nginx'
state: absent
\ No newline at end of file
vapormap ansible_host=10.29.246.136 ansible_user=ubuntu ansible_ssh_private_key_file=/home/user/Téléchargements/demo.pem
---
- name: "installation d' nginx"
apt:
name: nginx
state: present
become: yes
- name: "suppression"
file:
path: "{{ item }}"
state: absent
with_items:
- etc/nginx/sites-available/default
- etc/nginx/sites-enabled/default
- name: "création du fichier config.json"
template:
src: templates/config.json.j2
dest: /home/app-vapormap/vapormap-prod/frontend/config.json
remote_user: app-vapormap
become: yes
- name: "configuration nginx"
template:
src: templates/nginx.conf.j2
dest: /etc/nginx/sites-available/nginx.conf
owner: root
group: root
mode: 0644
become: yes
notify: "reload_nginx"
- name: "ajout au groupe www-data"
ansible.builtin.user:
name: app-vapormap
groups: www-data
append: yes
become: yes
- name: "lien symbolique"
file:
src: /etc/nginx/sites-available/nginx.conf
dest: /etc/nginx/sites-enabled/nginx.conf
state: link
- name: "lancer nginx"
systemd:
name: nginx
state: started
{ "apiUrl": "http://{{ansible_host}}:{{VAPORMAP_API_PORT}}" }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment