Commit 4ae9267e authored by Plup's avatar Plup

feature: refactored init and maitain tasks in playbooks

parent 57c38f37
---
- name: Check endpoints
become: no
gather_facts: no
hosts:
- apps
tasks:
- name: Check users endpoint
uri:
method: GET
url: "https://{{ server.address }}/users/"
status_code: 200
delegate_to: localhost
- name: Check prosody conference endpoint
uri:
method: GET
url: "{{ item }}"
status_code: 200
delegate_to: localhost
loop:
- "https://{{ xmpp.host }}/{{ xmpp.domain | default(client.address) }}/happydev_user_admin"
- "https://{{ xmpp.host }}/conference.{{ xmpp.domain | default(client.address) }}/happydev_muc_admin"
when:
- xmpp is defined
---
- name: Execute SQL commands
become: false
gather_facts: false
hosts:
- apps
vars_files:
- vars.yml
tasks:
- name: Get password
slurp:
src: "/home/{{ inventory_hostname }}/.dbpass"
register: postgresql_password_b64
no_log: true
- name: Drop notifications
postgresql_query:
db: "{{ inventory_hostname }}_db"
login_host: "postgresql-{{ inventory_hostname }}.alwaysdata.net"
login_password: "{{ postgresql_password_b64.content | b64decode }}"
login_user: "{{ inventory_hostname }}"
query: TRUNCATE djangoldp_notification_subscription;
delegate_to: localhost
tags:
- never
- drop-notif
---
- name: Federate instances together
become: false
gather_facts: false
hosts:
- all
vars:
target_instances: "{{ groups['hublworld'] + groups['happydev'] }}"
tasks:
- name: Federate instances
command: "python manage.py federate --target https://{{ hostvars[item].server.address }}"
environment:
PATH: "{{ home }}/venv/bin:/usr/local/bin:/usr/bin:/bin"
args:
chdir: "{{ home }}/sibserver/"
loop: "{{ target_instances }}"
register: cmd
when: not ansible_check_mode
changed_when: cmd.rc == 0
failed_when: cmd.rc > 1
...
---
- name: Update Alwaysdata websites
- name: Initialize applications
become: false
gather_facts: false
......@@ -15,25 +15,10 @@
plup:
urlid: https://api.paris.happy-dev.fr/users/plup/
tasks:
- name: Create and test subscriptions
block:
- command: "{{ home }}/venv/bin/python manage.py create_subscriptions"
args:
chdir: "{{ home }}/sibserver"
register: cmd
- name:
debug:
msg: "{{ cmd.stdout_lines }}"
tags:
- never
- subscriptions
tasks:
- name: Create an admin
- name: Create a remote admin
command: "python manage.py create_distant_admin --urlid='{{ known_users[user].urlid }}'"
environment:
PATH: "{{ home }}/venv/bin:/usr/local/bin:/usr/bin:/bin"
......@@ -62,18 +47,19 @@
- never
- create_local_admin
- name: Check integrity
block:
- command: "{{ home }}/venv/bin/python manage.py check_integrity"
args:
chdir: "{{ home }}/sibserver"
register: cmd
- name:
debug:
msg: "{{ cmd.stdout_lines }}"
- name: Federate applications
vars:
target_instances: "{{ groups['hublworld'] }}"
command: "python manage.py federate --target https://{{ hostvars[item].services.api }}"
environment:
PATH: "{{ home }}/venv/bin:/usr/local/bin:/usr/bin:/bin"
args:
chdir: "{{ home }}/sibserver/"
loop: "{{ target_instances }}"
register: cmd
when: not ansible_check_mode
changed_when: cmd.rc == 0
failed_when: cmd.rc > 1
tags:
- never
- check_integrity
- federate
......@@ -25,7 +25,6 @@ apps:
- type: admin
- type: about
- type: communities
title: Staging 1
- type: dashboard
- type: profileDirectory
- type: jobBoard
......@@ -62,10 +61,13 @@ apps:
- type: admin
- type: about
- type: communities
title: Staging 2
- type: dashboard
- type: profileDirectory
endpoints:
skills: https://api.stg1.startinblox.com/sources/skills/
- type: jobBoard
endpoints:
skills: https://api.stg1.startinblox.com/sources/skills/
- type: events
- type: projects
- type: invoice
......
---
- name: Maintainance tasks
become: false
gather_facts: false
hosts:
- apps
tasks:
## CHECKS
- block:
- name: Check users endpoint
uri:
method: GET
url: "https://{{ services.api }}/users/"
status_code: 200
delegate_to: localhost
- name: Check prosody conference endpoint
uri:
method: GET
url: "{{ item }}"
status_code: 200
delegate_to: localhost
loop:
- "https://{{ services.xmpp.host }}/{{ services.xmpp.domain | default(graphics.client) }}/happydev_user_admin"
- "https://{{ services.xmpp.host }}/conference.{{ services.xmpp.domain | default(graphics.client) }}/happydev_muc_admin"
when:
- services.xmpp is defined
tags:
- check_endpoints
- block:
- name: Check integrity
command: "{{ home }}/venv/bin/python manage.py check_integrity"
args:
chdir: "{{ home }}/sibserver"
register: cmd
- debug:
msg: "{{ cmd.stdout_lines }}"
tags:
- check_integrity
## OPERATIONS
- block:
- name: Create and test subscriptions
command: "{{ home }}/venv/bin/python manage.py create_subscriptions"
args:
chdir: "{{ home }}/sibserver"
register: cmd
- debug:
msg: "{{ cmd.stdout_lines }}"
tags:
- never
- subscriptions
- name: Put in maintenance mode
copy:
content: |
ErrorDocument 503 "This application is under maintenance. It's on the way back !"
Redirect 503 /
dest: "{{ home }}/client/dist/.htaccess"
tags:
- never
- maintenance_mode
- name: execute db commands
block:
- name: Get password
slurp:
src: "/home/{{ inventory_hostname }}/.dbpass"
register: postgresql_password_b64
no_log: true
tags:
- drop_notif
- name: Drop notifications
postgresql_query:
db: "{{ inventory_hostname }}_db"
login_host: "postgresql-{{ inventory_hostname }}.alwaysdata.net"
login_password: "{{ postgresql_password_b64.content | b64decode }}"
login_user: "{{ inventory_hostname }}"
query: TRUNCATE djangoldp_notification_subscription;
delegate_to: localhost
tags:
- drop_notif
tags:
- never
---
- name: Update Alwaysdata websites
become: false
gather_facts: false
hosts:
- apps
vars:
alwaysdata_api_key: "{{ vault_alwaysdata_api_key }}"
alwaysdata_app_account: '{{ inventory_hostname }}'
tasks:
- block:
- name: Get existing websites
include_role:
name: alwaysdata
tasks_from: site_retrieve.yml
#run_once: yes
- name: Get the current server and client config
set_fact:
server_config: "{{ alwaysdata_websites.json | selectattr('addresses', 'equalto', [(server.address + '/')]) | first | default(None) }}"
client_config: "{{ alwaysdata_websites.json | selectattr('addresses', 'equalto', [(client.address + '/')]) | first | default(None) }}"
- name: Update server config
include_role:
name: alwaysdata
tasks_from: site_update.yml
vars:
site:
id: "{{ server_config.href }}"
config:
name: sibserver
virtualenv_directory: /startinblox/venv
when:
- server_config != ""
- name: Update client config
include_role:
name: alwaysdata
tasks_from: site_update.yml
vars:
site:
id: "{{ client_config.href }}"
config:
name: client
path: /startinblox/client/dist/
when:
- client_config != ""
tags:
- never
- update_website
- name: Put in maintenance
copy:
content: |
ErrorDocument 503 "This application is under maintenance. It's on the way back !"
Redirect 503 /
dest: "{{ home }}/client/dist/.htaccess"
tags:
- never
- maintenance
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment