diff --git a/README.md b/README.md index 3637db8..6792290 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,70 @@ 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 the INCEpTION semantic annotation platform as Docker stack, 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 +inception_project_compose_dir: '/srv/inception_project_stack' +inception_project_docker_stack_name: 'inception-project' +inception_project_docker_service_name: 'inception' +inception_project_docker_image: 'inceptionproject/inception:0.17.3' +inception_project_docker_network: 'inception_project_net' +inception_project_docker_data_node: 'localhost' +# We need a directory because the confg file goes inside it +inception_project_service_volume: '/srv/inception_project_data' +inception_project_service_port: 8080 +# IMPORTANT. Set it to True for the server that is going to host the DB +inception_project_service_constraints: 'node.labels.service_data==inception_project' +inception_project_behind_haproxy: True +inception_project_haproxy_public_net: 'haproxy-public' +# Settings +inception_project_server_port: 8080 +inception_project_server_address: '0.0.0.0' +inception_project_backup_interval: 300 +inception_project_backup_keep_number: 10 +# In seconds +inception_project_backup_keep_time: 0 +inception_project_server_auth_mode: 'database' +inception_project_server_preauth_header: 'remote_user' +inception_project_server_preauth_default_roles: '' +inception_project_server_preauth_users_roles: [] +# - { username: 'user', roles: 'ROLE_PROJECT_CREATOR,ROLE_ADMIN' } +# DB +inception_project_db_as_container: True +inception_project_docker_db_node: 'localhost' +inception_project_db_image: 'mysql:5' +inception_project_db_host: 'mysql-server' +inception_project_db_port: 3306 +inception_project_db_name: 'inception' +inception_project_db_user: 'inception_user' +#inception_project_db_pwd: 'set it in a vault file' +inception_project_db_volume: 'inception_db_data' +inception_project_db_constraints: 'node.labels.mysql_data==inception_project' + +inception_project_settings: + - 'debug.showExceptionPage=false' + - 'user.profile.accessible=true' + - 'user-selection.hideUsers=false' + - 'server.port={{ inception_project_server_port }}' + - 'server.address={{ inception_project_server_address }}' + - 'server.ajp.port=-1' + - 'backup.interval={{ inception_project_backup_interval }}' + - 'backup.keep.number={{ inception_project_backup_keep_number }}' + - 'backup.keep.time={{ inception_project_backup_keep_time }}' + - 'auth.mode={{ inception_project_server_auth_mode }}' + - 'auth.preauth.header.principal={{ inception_project_server_preauth_header }}' + - 'auth.preauth.newuser.roles={{ inception_project_server_preauth_default_roles }}' +``` 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 License ------- @@ -35,4 +74,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, diff --git a/defaults/main.yml b/defaults/main.yml index 95d3c70..b94e920 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,2 +1,51 @@ --- -# defaults file for ansible-role-template \ No newline at end of file +inception_project_compose_dir: '/srv/inception_project_stack' +inception_project_docker_stack_name: 'inception-project' +inception_project_docker_service_name: 'inception' +inception_project_docker_image: 'inceptionproject/inception:0.17.3' +inception_project_docker_network: 'inception_project_net' +inception_project_docker_data_node: 'localhost' +# We need a directory because the confg file goes inside it +inception_project_service_volume: '/srv/inception_project_data' +inception_project_service_port: 8080 +# IMPORTANT. Set it to True for the server that is going to host the DB +inception_project_service_constraints: 'node.labels.service_data==inception_project' +inception_project_behind_haproxy: True +inception_project_haproxy_public_net: 'haproxy-public' +# Settings +inception_project_server_port: 8080 +inception_project_server_address: '0.0.0.0' +inception_project_backup_interval: 300 +inception_project_backup_keep_number: 10 +# In seconds +inception_project_backup_keep_time: 0 +inception_project_server_auth_mode: 'database' +inception_project_server_preauth_header: 'remote_user' +inception_project_server_preauth_default_roles: '' +inception_project_server_preauth_users_roles: [] +# - { username: 'user', roles: 'ROLE_PROJECT_CREATOR,ROLE_ADMIN' } +# DB +inception_project_db_as_container: True +inception_project_docker_db_node: 'localhost' +inception_project_db_image: 'mysql:5' +inception_project_db_host: 'mysql-server' +inception_project_db_port: 3306 +inception_project_db_name: 'inception' +inception_project_db_user: 'inception_user' +#inception_project_db_pwd: 'set it in a vault file' +inception_project_db_volume: 'inception_db_data' +inception_project_db_constraints: 'node.labels.mysql_data==inception_project' + +inception_project_settings: + - 'debug.showExceptionPage=false' + - 'user.profile.accessible=true' + - 'user-selection.hideUsers=false' + - 'server.port={{ inception_project_server_port }}' + - 'server.address={{ inception_project_server_address }}' + - 'server.ajp.port=-1' + - 'backup.interval={{ inception_project_backup_interval }}' + - 'backup.keep.number={{ inception_project_backup_keep_number }}' + - 'backup.keep.time={{ inception_project_backup_keep_time }}' + - 'auth.mode={{ inception_project_server_auth_mode }}' + - 'auth.preauth.header.principal={{ inception_project_server_preauth_header }}' + - 'auth.preauth.newuser.roles={{ inception_project_server_preauth_default_roles }}' diff --git a/meta/main.yml b/meta/main.yml index 81bda14..7b40f24 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,46 +1,26 @@ galaxy_info: - author: your name - description: your description - company: your company (optional) + 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://support.d4science.org/projects/automatic-provisioning/issues + issue_tracker_url: https://support.d4science.org/projects/d4science-operation - 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: Ubuntu - versions: - - bionic + - 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. + galaxy_tags: + - inception-project dependencies: [] - # List your role dependencies here, one per line. Be sure to remove the '[]' above, - # if you add dependencies to this list. \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index 53c6cae..d8e884d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,48 @@ --- -# tasks file for ansible-role-template \ No newline at end of file +- name: Manage the installation of the Inception configuration of the swarm service + block: + - name: Create the data directory used by the inception service, and its subdirectories + file: dest={{ inception_project_service_volume }}/{{ item }} state=directory + with_items: + - 'repository/kb' + - 'plugins' + + - name: Install the inception properties file + template: src=settings.properties.j2 dest={{ inception_project_service_volume }}/settings.properties owner=root group=root mode='0444' + + when: inception_project_docker_data_node == ansible_fqdn + tags: [ 'inception_project', 'inception_project_swarm' ] + +- name: Manage the installation of the Inception project Docker stack + block: + - name: Create the directory where the compose file will be installed + file: dest={{ inception_project_compose_dir }} state=directory mode='0750' owner=root group=root + + - name: Install the docker compose file + template: src=inception-project-docker-compose.yml.j2 dest={{ inception_project_compose_dir }}/docker-inception-project-stack.yml owner=root group=root mode='0400' + + - name: Add the label that will be used as a constraint for the inception data volume + docker_node: + hostname: '{{ inception_project_docker_data_node }}' + labels: + service_data: 'inception_project' + labels_state: 'merge' + + - name: Add the label that will be used as a constraint for the MySQL DB + docker_node: + hostname: '{{ inception_project_docker_db_node }}' + labels: + mysql_data: 'inception_project' + labels_state: 'merge' + when: inception_project_db_as_container + + - name: Start the Inception project stack + docker_stack: + name: inception-project + state: present + compose: + - '{{ inception_project_compose_dir }}/docker-inception-project-stack.yml' + + run_once: True + when: docker_swarm_manager_main_node is defined and docker_swarm_manager_main_node | bool + tags: [ 'inception_project', 'inception_project_swarm' ] diff --git a/templates/inception-project-docker-compose.yml.j2 b/templates/inception-project-docker-compose.yml.j2 new file mode 100644 index 0000000..1eb956f --- /dev/null +++ b/templates/inception-project-docker-compose.yml.j2 @@ -0,0 +1,78 @@ +version: '3.6' + +networks: +{% if inception_project_behind_haproxy %} + haproxy-public: + external: true +{% endif %} + {{ inception_project_docker_network }}: + +volumes: + {{ inception_project_db_volume }}: +# {{ inception_project_service_volume }}: + +services: + {{ inception_project_docker_service_name }}: + image: {{ inception_project_docker_image }} + networks: + - {{ inception_project_docker_network }} +{% if inception_project_behind_haproxy %} + - haproxy-public +{% endif %} + environment: + - INCEPTION_DB_DIALECT=org.hibernate.dialect.MySQL5InnoDBDialect + - INCEPTION_DB_DRIVER=com.mysql.jdbc.Driver + - INCEPTION_DB_URL=jdbc:mysql://{{ inception_project_db_host }}:{{ inception_project_db_port }}/{{ inception_project_db_name }}?useSSL=false&useUnicode=true&characterEncoding=UTF-8 + - INCEPTION_DB_USERNAME={{ inception_project_db_user }} + - INCEPTION_DB_PASSWORD={{ inception_project_db_pwd }} + volumes: + - {{ inception_project_service_volume }}:/export + depends_on: + - {{ inception_project_db_host }} + deploy: + mode: replicated + replicas: 1 + endpoint_mode: dnsrr + placement: + constraints: + - node.role == worker + - {{ inception_project_service_constraints }} + restart_policy: + condition: on-failure + delay: 5s + max_attempts: 3 + window: 120s + logging: + driver: 'journald' +{% if inception_project_db_as_container %} + {{ inception_project_db_host }}: + image: {{ inception_project_db_image }} + networks: + - {{ inception_project_docker_network }} + volumes: + - {{ inception_project_db_volume }}:/var/lib/mysql + environment: + - MYSQL_RANDOM_ROOT_PASSWORD=yes + - MYSQL_DATABASE={{ inception_project_db_name }} + - MYSQL_USER={{ inception_project_db_user }} + - MYSQL_PORT=3306 + - MYSQL_PASSWORD={{ inception_project_db_pwd }} + command: ["--character-set-server=utf8", "--collation-server=utf8_bin"] + healthcheck: + test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost", "-p{{ inception_project_db_pwd }}", "-u{{ inception_project_db_user }}"] + interval: 20s + timeout: 10s + retries: 10 + deploy: + placement: + constraints: + - node.role == worker + - {{ inception_project_db_constraints }} + restart_policy: + condition: on-failure + delay: 5s + max_attempts: 3 + window: 120s + logging: + driver: 'journald' +{% endif %} diff --git a/templates/settings.properties.j2 b/templates/settings.properties.j2 new file mode 100644 index 0000000..aea4a7f --- /dev/null +++ b/templates/settings.properties.j2 @@ -0,0 +1,8 @@ +warnings.unsupportedBrowser=false +{% for setting in inception_project_settings %} +{{ setting }} +{% endfor %} +{% for user_role in inception_project_server_preauth_users_roles %} +auth.user.{{ user_role.username }}.roles={{ user_role.roles }} +{% endfor %} + diff --git a/vars/main.yml b/vars/main.yml index 3808477..57f0f0f 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,2 @@ --- -# vars file for ansible-role-template \ No newline at end of file +psql_db_data: '{{ inception_project_psql_db_data }}'