maintain.yml 2.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
---
- 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