diff --git a/group_vars/constellation.yml b/group_vars/constellation.yml new file mode 100644 index 0000000000000000000000000000000000000000..a9c30bde9b7038d477efe201d32f61422a5a0bf6 --- /dev/null +++ b/group_vars/constellation.yml @@ -0,0 +1,31 @@ +--- +glob_constellation: + django_secret_key: "{{ vault.constellation_django_secret_key }}" + admins: + - ('Root', 'root@crans.org') + allowed_hosts: + - 'constellation.crans.org' + - 'intranet.crans.org' + email: + ssl: false + host: "{{ query('ldap', 'ip', 'redisdead', 'adm') | ipv4 | first }}" + port: 25 + user: '' + password: '' + from: "root@crans.org" + from_full: "Crans <root@crans.org>" + database: + host: "{{ query('ldap', 'ip', 'tealc', 'adm') | ipv4 | first }}" + port: 5432 + user: 'constellation' + password: "{{ vault.constellation_django_db_password }}" + name: 'constellation' + comnpay: + tpe: 'VAD-941-415' + secret: '{{ vault.comnpay_secret }}' + debug: false + owner: root + group: nounou + version: master + settings_local_owner: www-data + settings_local_group: nounou diff --git a/host_vars/constellation-dev.adm.crans.org.yml b/host_vars/constellation-dev.adm.crans.org.yml index 5cde204461d4051fcc160eab974a5c25e3663a6c..01fe3788919e8ac144352537ab2d72caee878519 100644 --- a/host_vars/constellation-dev.adm.crans.org.yml +++ b/host_vars/constellation-dev.adm.crans.org.yml @@ -1,3 +1,12 @@ --- interfaces: adm: eth0 + +loc_constellation: + allowed_hosts: + - 'constellation-dev.crans.org' + comnpay: + tpe: 'HOM-832-854' + secret: '{{ vault.comnpay_homologation_secret }}' + debug: true + version: comnpay diff --git a/plays/constellation.yml b/plays/constellation.yml new file mode 100755 index 0000000000000000000000000000000000000000..cb18e246b981acb089d6461e63807b27fcdbad98 --- /dev/null +++ b/plays/constellation.yml @@ -0,0 +1,7 @@ +#!/usr/bin/env ansible-playbook +--- +- hosts: constellation + vars: + constellation: "{{ glob_constellation | combine(loc_constellation | default({})) }}" + roles: + - constellation diff --git a/roles/constellation/tasks/main.yml b/roles/constellation/tasks/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..1d7f58a8291be48b47130d684beb22410369be50 --- /dev/null +++ b/roles/constellation/tasks/main.yml @@ -0,0 +1,70 @@ +--- +- name: Install constellation dependencies + apt: + update_cache: true + install_recommends: false + name: + - python3-django + - python3-django-crispy-forms + - python3-django-extensions + - python3-django-polymorphic + - python3-djangorestframework + - python3-django-tables2 + - python3-ipython + - python3-pip + - python3-psycopg2 + register: apt_result + retries: 3 + until: apt_result is succeeded + +- name: Install constellation pip dependencies + pip: + name: + - django-dnsmanager>=0.2.1 + +- name: Create constellation directory + file: + path: /var/local/constellation + state: directory + mode: '2775' + owner: "{{ constellation.owner }}" + group: "{{ constellation.group }}" + +- name: Set ACL for constellation directory + acl: + path: /var/local/constellation + default: true + entity: nounou + etype: group + permissions: rwx + state: query + ignore_errors: "{{ ansible_check_mode }}" + +- name: Clone constellation repository + git: + repo: 'https://gitlab.adm.crans.org/nounous/constellation.git' + dest: /var/local/constellation + umask: '002' + version: "{{ constellation.version }}" + recursive: true + +- name: Set owner of cloned project + file: + path: /var/local/constellation + owner: "{{ constellation.owner }}" + group: "{{ constellation.group }}" + recurse: true + +- name: Indicate constellation in motd + template: + src: update-motd.d/05-service.j2 + dest: /etc/update-motd.d/05-constellation + mode: 0755 + +- name: Deploy Constellation settings_local.py + template: + src: constellation/settings_local.py.j2 + dest: /var/local/constellation/constellation/settings_local.py + mode: 0660 + owner: "{{ constellation.settings_local_owner }}" + group: "{{ constellation.settings_local_group }}" diff --git a/roles/constellation/templates/constellation/settings_local.py.j2 b/roles/constellation/templates/constellation/settings_local.py.j2 new file mode 100644 index 0000000000000000000000000000000000000000..9b0810fe0e3a4b6e8b68a9d2d00f302ba6e622e9 --- /dev/null +++ b/roles/constellation/templates/constellation/settings_local.py.j2 @@ -0,0 +1,43 @@ +# -*- mode: python; coding: utf-8 -*- +{{ ansible_header | comment }} + +# A secret key used by the server. +SECRET_KEY = '{{ constellation.django_secret_key }}' + +# Should the server run in debug mode ? +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = {{ constellation.debug }} + +# A list of admins of the services. Receive mails when an error occurs +ADMINS = [{% for admin in constellation.admins %}{{ admin }}, {% endfor %}] + +# The list of hostname the server will respond to. +ALLOWED_HOSTS = [{% for host in constellation.allowed_hosts %}'{{ host }}', {% endfor %}] + +# The time zone the server is runned in +TIME_ZONE = 'Europe/Paris' + +# The storage systems parameters to use +DATABASES = { + 'default': { # The DB + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': '{{ constellation.database.name }}', + 'USER': '{{ constellation.database.user }}', + 'PASSWORD': '{{ constellation.database.password }}', + 'HOST': '{{ constellation.database.host }}', + 'PORT': '{{ constellation.database.port }}', + }, +} + +# The mail configuration for Constellation to send mails +EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' +EMAIL_USE_SSL = {{ constellation.email.ssl }} +EMAIL_HOST = '{{ constellation.email.host }}' +EMAIL_PORT = {{ constellation.email.port }} +EMAIL_HOST_USER = '{{ constellation.email.user }}' +EMAIL_HOST_PASSWORD = '{{ constellation.email.password }}' +SERVER_EMAIL = '{{ constellation.email.from }}' +DEFAULT_FROM_EMAIL = '{{ constellation.email.from_full }}' + +COMNPAY_ID_TPE = '{{ constellation.comnpay.tpe }}' +COMNPAY_SECRET_KEY = '{{ constellation.comnpay.secret }}' diff --git a/roles/constellation/templates/update-motd.d/05-service.j2 b/roles/constellation/templates/update-motd.d/05-service.j2 new file mode 100755 index 0000000000000000000000000000000000000000..a13717c87123844cac38ec3f5b58fb43f961be35 --- /dev/null +++ b/roles/constellation/templates/update-motd.d/05-service.j2 @@ -0,0 +1,3 @@ +#!/usr/bin/tail +14 +{{ ansible_header | comment }} +[0m> [38;5;82mConstellation[0m a été déployé sur cette machine. Voir [38;5;6m/var/www/constellation/[0m.