Role that installs the epas server.

This commit is contained in:
Andrea Dell'Amico 2020-10-26 15:48:35 +01:00
parent d66fb98256
commit 85496a65a5
7 changed files with 311 additions and 70 deletions

View File

@ -1,31 +1,69 @@
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
A role that installs ePAS, electronic Personnel Attendance System. <https://epas.projects.iit.cnr.it>
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
The most important variables are listed below:
``` yaml
epas_docker_stack_name: 'epas_prod'
epas_docker_service_server_name: 'epas'
epas_docker_registry: 'docker-registry.services.iit.cnr.it'
epas_docker_server_image: '{{ epas_docker_registry }}/epas/epas:stable'
epas_docker_registry_user: 'epas.user'
epas_docker_registry_pwd: 'use a vault file'
epas_docker_network: 'epas_net'
epas_attachments_node: 'localhost'
epas_attachments_volume: 'epas_attachments_data'
epas_node_constraints: 'node.labels.epas_storage == attachments'
epas_behind_haproxy: True
epas_haproxy_public_net: 'haproxy-public'
# DB
# Set to true if postgresql must be a container too
epas_dockerized_db: False
# IMPORTANT. Set it to True for the server that is going to host the DB
epas_docker_db_node: False
epas_pg_version: '12'
epas_db_image: 'postgres:{{ epas_pg_version }}-alpine'
# The default hostname is the name of the container service
epas_db_host: 'postgres'
epas_db_name: 'epas_prod_db'
epas_db_allowed_hosts:
- '127.0.0.1'
#epas_db_pwd: 'set it in a vault file'
epas_db_user: 'epas_prod_user'
epas_db_volume: 'epas_prod_pg_data'
epas_db_constraints: '[node.labels.pg_data==epas_db]'
epas_pg_data_volume: 'epas_db_data'
epas_pg_backups_volume: 'epas_db_data'
psql_db_data: '{{ epas_psql_pg_data }}'
# Environment
epas_server_hostname: 'epas.example.com'
## SMTP
epas_smtp_server: 'localhost'
epas_smtp_port: 587
epas_smtp_channel: 'starttls'
epas_smtp_from: 'epas@cnr.it'
epas_smtp_protocol: 'smtp'
epas_smtp_authentication: True
epas_smtp_user: ''
epas_smtp_password: 'use a vault file'
## LDAP
epas_ldap_login: 'false'
epas_ldap_url: 'ldap://ldap.example.org:389'
epas_ldap_timeout: 1000
epas_ldap_base_dn: 'ou=People,dc=example,dc=org'
epas_ldap_login_return_uri: '/.'
epas_ldap_eppn_attribute_name: 'eduPersonPrincipalName'
```
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
A docker swarm cluster is required
License
-------
@ -35,4 +73,4 @@ EUPL-1.2
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
Andrea Dell'Amico, <andrea.dellamico@isti.cnr.it>

View File

@ -1,2 +1,49 @@
---
# defaults file for ansible-role-template
epas_docker_stack_name: 'epas_prod'
epas_docker_service_server_name: 'epas'
epas_docker_registry: 'docker-registry.services.iit.cnr.it'
epas_docker_server_image: '{{ epas_docker_registry }}/epas/epas:stable'
epas_docker_registry_user: 'epas.user'
epas_docker_registry_pwd: 'use a vault file'
epas_docker_network: 'epas_net'
epas_docker_attachments_node: 'localhost'
epas_attachments_volume: 'epas_attachments_data'
epas_node_constraints: 'node.labels.epas_storage == attachments'
epas_behind_haproxy: True
epas_haproxy_public_net: 'haproxy-public'
# DB
# Set to true if postgresql must be a container too
epas_dockerized_db: False
epas_pg_version: '12'
epas_db_image: 'postgres:{{ epas_pg_version }}-alpine'
# The default hostname is the name of the container service
epas_db_host: 'postgres'
epas_db_name: 'epas_prod_db'
epas_db_allowed_hosts:
- '127.0.0.1'
#epas_db_pwd: 'set it in a vault file'
epas_db_user: 'epas_prod_user'
epas_docker_db_node: 'localhost'
epas_db_volume: 'epas_prod_pg_data'
epas_db_constraints: '[node.labels.epas_pg_data==epas_db]'
epas_pg_data_volume: 'epas_db_data'
epas_pg_backups_volume: 'epas_db_data'
psql_db_data: '{{ epas_psql_pg_data }}'
# Environment
epas_server_hostname: 'epas.example.com'
## SMTP
epas_smtp_server: 'localhost'
epas_smtp_port: 587
epas_smtp_channel: 'starttls'
epas_smtp_from: 'epas@cnr.it'
epas_smtp_protocol: 'smtp'
epas_smtp_authentication: True
epas_smtp_user: ''
epas_smtp_password: 'use a vault file'
## LDAP
epas_ldap_login: 'false'
epas_ldap_url: 'ldap://ldap.example.org:389'
epas_ldap_timeout: 1000
epas_ldap_base_dn: 'ou=People,dc=example,dc=org'
epas_ldap_login_return_uri: '/.'
epas_ldap_eppn_attribute_name: 'eduPersonPrincipalName'

View File

@ -1,61 +1,31 @@
galaxy_info:
author: your name
description: your description
author: Andrea Dell'Amico
description: Systems Architect
company: ISTI-CNR
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
issue_tracker_url: https://redmine-s2i2s.isti.cnr.it/projects/provisioning
issue_tracker_url: https://support.d4science.org/projects/d4science-operation
# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: EUPL-1.2
license: EUPL 1.2+
min_ansible_version: 2.8
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
# Optionally specify the branch Galaxy will use when accessing the GitHub
# repo for this role. During role install, if no tags are available,
# Galaxy will use this branch. During import Galaxy will access files on
# this branch. If Travis integration is configured, only notifications for this
# branch will be accepted. Otherwise, in all cases, the repo's default branch
# (usually master) will be used.
#github_branch:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
platforms:
- name: Ubuntu
versions:
- bionic
- name: EL
versions:
- 7
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
galaxy_tags:
- epas
dependencies:
- src: git+https://gitea-s2i2s.isti.cnr.it/ISTI-ansible-roles/ansible-role-pgsql-db-management.git
version: master
name: pgsql-db-management
state: latest
when: not epas_dockerized_db

View File

@ -1,2 +1,55 @@
---
# tasks file for ansible-role-template
- name: Manage the installation of the ePAS configuration of the swarm service
block:
- name: Create the directory where the DB init script is going to be installed
file: dest={{ epas_compose_dir }} state=directory
- name: Install the DB initialization script
template: src=pg-create-user-db.sh.j2 dest={{ epas_compose_dir }}/pg-create-user-db.sh owner=root group=root mode='0555'
run_once: True
when:
- epas_dockerized_db
- epas_docker_db_node == ansible_fqdn
tags: [ 'epas', 'epas_swarm', 'epas_db' ]
- name: Manage the installation of the ePAS configuration of the swarm service
block:
- name: Add the label that will be used as a constraint for the attachments volume
docker_node:
hostname: '{{ epas_docker_attachments_node }}'
labels:
epas_storage: 'attachments'
labels_state: '{{ docker_label_state_mode }}'
- name: Add the label that will be used as a constraint for the postgresql DB
docker_node:
hostname: '{{ epas_docker_db_node }}'
labels:
epas_pg_data: 'epas_db'
labels_state: '{{ docker_label_state_mode }}'
- name: Install the docker compose file
template: src=epas-docker-compose.yml.j2 dest={{ epas_compose_dir }}/docker-epas-stack.yml owner=root group=root mode='0400'
- name: Login into the IIT registry
shell: docker login -u {{ epas_docker_registry_user }} -p {{ epas_docker_registry_pwd }} {{ epas_docker_registry }}
- name: Start the ePAS stack
docker_stack:
name: '{{ epas_docker_stack_name }}'
state: present
with_registry_auth: True
compose:
- '{{ epas_compose_dir }}/docker-epas-stack.yml'
# - name: Connect the ePAS service to the haproxy-public network
# command: docker service update --network-add {{ epas_haproxy_public_net }} {{ item }} --update-delay 30s --update-parallelism 1
# with_items:
# - '{{ epas_docker_stack_name }}_{{ epas_docker_service_server_name }}'
# ignore_errors: True
# when: epas_behind_haproxy
run_once: True
when: docker_swarm_manager_main_node is defined and docker_swarm_manager_main_node | bool
tags: [ 'epas', 'epas_swarm', 'epas_server' ]

View File

@ -0,0 +1,118 @@
version: '3.2'
networks:
{{ epas_haproxy_public_net }}:
external: true
{{ epas_docker_network }}:
volumes:
{{ epas_attachments_volume }}:
{% if epas_dockerized_db %}
{{ epas_pg_backups_volume }}:
{{ epas_db_volume }}:
{% endif %}
services:
{{ epas_docker_service_server_name }}:
image: {{ epas_docker_server_image }}
networks:
- {{ epas_docker_network }}
- {{ epas_haproxy_public_net }}
volumes:
- {{ epas_attachments_volume }}:/home/epas/epas/data/attachments
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
environment:
- VIRTUAL_HOST={{ epas_server_hostname }}
- PROTOCOL=https # default: http -- (http,https)
# - EPAS_SHIB_LOGIN= # default: false -- (true,false)
- JOBS_ACTIVE=true # default: false -- (true,false) -- Se forzato a true abilita l'esecuzione di tutti i job
# - SKIP_IP_CHECK= # default: false -- (true,false) -- Disabilita il controllo sugli indirizzi ip delle richieste
- FLOWS_ACTIVE=true
# - URL_ATTESTATI= # default: https://attestativ2.rm.cnr.it
# - URL_USER=
# - URL_PASS=
######## LOGS ###########
# - LOG_LEVEL= # Opzionale. default: INFO -- (OFF,FATAL,ERROR,WARN,INFO,DEBUG,TRACE,ALL)
- APPENDERS=stderr # Opzionale. default: stdout, stderr -- (stdout, stderr, file, graylog2). Abilita i log sulla console, file e server graylog
# - GRAYLOG_HOST= # Obbligatorio se attivato log sull'appender graylog2. default: null
# - GRAYLOG_PORT= # Opzionale. default: 3514
# - GRAYLOG_ORIGIN_HOST= # Opzionale. default: valore in VIRTUAL_HOST
###### Container ########
# - BACKUP_CRON= # default: disattivato. (utilizzare il format del crontab. Es. 0 0 * * *)
# - CERT_NAME= # default: valore specificato in VIRTUAL_HOST -- Specifica un nome diverso per i file del certificato SSL
- TZ=Europe/Rome
#### Connessione DB ####
- DB_HOST={{ epas_db_host }} # default: indirizzo assegnato al container postgres linkato
- DB_NAME={{ epas_db_name }} # default: epas
- DB_PASS='{{ epas_db_pwd }}' # default: "non necessaria"
- DB_PORT=5432 # default: 5432
- DB_USER={{ epas_db_user }} # default: postgres
#### server SMTP ####
- SMTP_HOST={{ epas_smtp_server }} # default: smtp.cnr.it
- SMTP_PORT={{ epas_smtp_port }} # default: 25 se SMTP_CHANNEL è impostato clear o starttls; 465 se impostato su ssl
- SMTP_CHANNEL={{ epas_smtp_channel }} # default: clear -- (clear, ssl ,starttls)
- SMTP_FROM={{ epas_smtp_from }} # default: epas@cnr.it -- Indirizzo utilizzato per il campo mittente delle mail inviate dal sistema
- SMTP_PROTOCOL={{ epas_smtp_protocol}} # default: smtp -- (smtp, smtps)
{% if epas_smtp_authentication %}
- SMTP_USER={{ epas_smtp_user }} # user utilizzato per l'autenticazione sul server smtp (se necessario)
- SMTP_PASS={{ epas_smtp_password }} # password utilizzato per l'autenticazione sul server smtp (se necessaria)
{% endif %}
#### Autenticazione LDAP ####
- LDAP_LOGIN={{ epas_ldap_login }} # default: false. Impostare a true per attivare l'autenticazione tramite LDAP
- LDAP_URL={{ epas_ldap_url }} # url del server LDAP, per esempio ldap://ldap.cnr.it:389
- LDAP_TIMEOUT={{ epas_ldap_timeout }} # default: 1000. Time in millisecondi della connessione LDAP.
- LDAP_DN_BASE={{ epas_ldap_base_dn }} # DN per la ricerca degli utenti su LDAP, per esempio ou=People,dc=iit,dc=cnr,dc=it
- LDAP_LOGIN_RETURN={{ epas_ldap_login_return_uri }} # default: /. Indirizzo relativo di reindirizzamento dopo il login LDAP.
- LDAP_EPPN_ATTRIBUTE_NAME={{ epas_ldap_eppn_attribute_name }} # default: eduPersonPrincipalName. Campo LDAP utilizzato per il mapping con il campo eppn presente in ePAS.
#### Invio Segnalazioni via email
#- REPORT_TO=${REPORT_TO} # default: epas@iit.cnr.it
#- REPORT_FROM=${REPORT_FROM} # default: segnalazioni@epas.tools.iit.cnr.it
#- REPORT_SUBJECT=${REPORT_SUBJECT} # default: Segnalazione ePAS
deploy:
mode: replicated
replicas: 1
endpoint_mode: dnsrr
placement:
constraints:
- node.role == worker
- {{ epas_node_constraints }}
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
logging:
driver: 'journald'
{% if epas_dockerized_db %}
postgres:
image: {{ epas_db_image }}
environment:
POSTGRES_PASSWORD: {{ epas_db_pwd }}
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PORT: 5432
PGDATA: /var/lib/postgresql/data/pg_data
networks:
- {{ epas_docker_network }}
volumes:
- {{ epas_pg_data_volume }}:/var/lib/postgresql/data/pg_data
- {{ epas_pg_backups_volume }}:/tmp:ro
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
deploy:
mode: replicated
replicas: 1
endpoint_mode: dnsrr
placement:
constraints: {{ epas_db_constraints }}
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
logging:
driver: 'journald'
{% endif %}

View File

@ -0,0 +1,12 @@
#!/bin/bash
set -e
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE USER {{ epas_db_user }} password '{{ epas_db_pwd }}';
CREATE DATABASE {{ epas_db_name }}
OWNER {{ epas_db_user }}
ENCODING UTF8 LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8'
TEMPLATE template0;
GRANT ALL PRIVILEGES ON DATABASE {{ epas_db_name }} TO {{ epas_db_user }};
EOSQL

View File

@ -1,2 +1,5 @@
---
# vars file for ansible-role-template
epas_compose_dir: '/srv/epas_stack'
epas_psql_pg_data:
- { db_host: '{{ epas_db_host }}', pgsql_version: '{{ epas_pg_version }}', name: '{{ epas_db_name }}', encoding: 'UTF8', user: '{{ epas_db_user }}', roles: 'NOCREATEDB,NOSUPERUSER', pwd: '{{ epas_db_pwd }}', managedb: True, allowed_hosts: '{{ epas_db_allowed_hosts }}' }