diff --git a/defaults/main.yml b/defaults/main.yml index a21f7ab75c9870f504e4f48a9f659f4e2192eb94..7f22686cd043f1f7cbe87f71da9c3f0632e055aa 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1 +1 @@ -alerta_ui_version: '7.0.1' +alerta_ui_version: 7.0.1 diff --git a/handlers/main.yml b/handlers/main.yml index db51e0acf16796c5aa03da4d1ba20c3b410a242c..e79788d5eebf69d2502c566a88e8d098a19a6f29 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,4 +1,4 @@ -- name: "Restart uwsgi" +- name: Restart uwsgi service: - name: 'uwsgi' - state: 'restarted' + name: uwsgi + state: restarted diff --git a/tasks/alerta.yml b/tasks/alerta.yml index 24c0ecd07723cbeeb4892390093415e1c9ca0744..8e82625c190c93b8e4048bf5555a15d7a156d030 100644 --- a/tasks/alerta.yml +++ b/tasks/alerta.yml @@ -1,130 +1,133 @@ --- # file: roles/alerta/tasks/alerta.yml -- name: "Ensure packages" +- name: Ensure packages apt: pkg: '{{ packages }}' - state: 'present' + state: present vars: packages: - - 'python-pip' - - 'python-dev' - - 'python3-dev' - - 'libpq-dev' + - python-pip + - python-dev + - python3-dev + - libpq-dev -- name: "Ensure PIP packages" +- name: Ensure PIP packages pip: name: '{{ packages }}' - state: 'present' + state: present vars: packages: - - 'alerta-server' - - 'alerta' - - 'uwsgi' - - 'python-gitlab' + - alerta-server + - alerta + - uwsgi + - python-gitlab -- name: "Remove directories for web UI" +- name: Remove directories for web UI file: path: '{{ item }}' - state: 'absent' + state: absent with_items: - - '/var/www/alerta' - - '/tmp/angular-alerta-webui-master' + - /var/www/alerta + - /tmp/angular-alerta-webui-master # docker run -d -v "/var/www/alerta/config.json:/usr/share/nginx/html/config.json" --restart=always -it -p 8999:80 --name alerta-beta alerta/alerta-beta -- name: "Download and extract web UI" +- name: Download and extract web UI unarchive: - src: 'https://github.com/alerta/angular-alerta-webui/archive/v{{ alerta_ui_version }}.zip' - dest: '/tmp' + src: https://github.com/alerta/angular-alerta-webui/archive/v{{ alerta_ui_version }}.zip + dest: /tmp remote_src: yes -- name: "Move new web UI" - command: 'mv /tmp/angular-alerta-webui-{{ alerta_ui_version }}/app /var/www/alerta' +- name: Move new web UI + command: mv /tmp/angular-alerta-webui-{{ alerta_ui_version }}/app /var/www/alerta args: - creates: '/var/www/alerta' - removes: '/tmp/angular-alerta-webui-{{ alerta_ui_version }}/app' + creates: /var/www/alerta + removes: /tmp/angular-alerta-webui-{{ alerta_ui_version }}/app -- name: "Copy wsgi.py" +- name: Copy wsgi.py template: - src: 'wsgi.py' - dest: '/var/www/alerta/wsgi.py' + src: wsgi.py + dest: /var/www/alerta/wsgi.py -- name: "Copy uwsgi.ini" +- name: Copy uwsgi.ini template: - src: 'uwsgi.ini' - dest: '/etc/uwsgi.ini' + src: uwsgi.ini + dest: /etc/uwsgi.ini -- name: "Copy uwsgi.service" +- name: Copy uwsgi.service template: - src: 'uwsgi.service' - dest: '/etc/systemd/system/uwsgi.service' + src: uwsgi.service + dest: /etc/systemd/system/uwsgi.service -- name: "Prepare uwsgi for autostart" +- name: Prepare uwsgi for autostart systemd: - name: 'uwsgi' - state: 'restarted' + name: uwsgi + state: restarted enabled: yes daemon_reload: yes -- name: "Copy nginx default config" +- name: Copy nginx default config template: - src: 'nginx.default' - dest: '/etc/nginx/sites-available/default' + src: nginx.default + dest: /etc/nginx/sites-available/default notify: - "Restart nginx" -- name: "Copy config.js" +- name: Copy config.js template: src: '{{ item }}' - dest: '/var/www/alerta/{{ item }}' + dest: /var/www/alerta/{{ item }} with_items: - - 'config.js' - - 'config.json' + - config.js + - config.json -- name: "Copy alertad.conf" +- name: Copy alertad.conf template: - src: 'alertad.conf' - dest: '/etc/alertad.conf' + src: alertad.conf + dest: /etc/alertad.conf notify: - "Restart uwsgi" -- name: "Configure root CLI" +- name: Configure root CLI template: - src: 'alerta.conf' - dest: '/root/.alerta.conf' + src: alerta.conf + dest: /root/.alerta.conf -- name: "Configure crontabs" +- name: Configure crontabs cron: name: '{{ item.name }}' minute: '{{ item.minute }}' job: '{{ item.job }} >/dev/null 2>&1' disabled: '{{ crons_disabled|default(false) }}' with_items: - - name: 'Heartbeats to Alert' - minute: '*/3' - job: '/usr/local/bin/alerta heartbeats --alert' - - name: 'Alerta Housekeeping' - minute: '0' - job: '/usr/local/bin/alerta housekeeping' - tags: 'cron' - -- name: "Copy Gitlab plugin" + - name: Heartbeats to Alert + minute: */3 + job: /usr/local/bin/alerta heartbeats --alert + - name: Alerta Housekeeping + minute: 0 + job: /usr/local/bin/alerta housekeeping + tags: + - cron + +- name: Copy Gitlab plugin template: - src: 'gitlab/{{ item }}' - dest: '/tmp/{{ item }}' + src: gitlab/{{ item }} + dest: /tmp/{{ item }} with_items: - - 'alerta_gitlab.py' - - 'setup.py' - tags: 'plugin' + - alerta_gitlab.py + - setup.py + tags: + - plugin -- name: "Install Gitlab plugin" - command: 'python3 setup.py install' +- name: Install Gitlab plugin + command: python3 setup.py install args: - chdir: '/tmp' - tags: 'plugin' + chdir: /tmp + tags: + - plugin -- name: "Copy favicon.ico" +- name: Copy favicon.ico copy: src: '{{ inventory_dir }}/files/favicon.ico' - dest: '/var/www/alerta/favicon.ico' + dest: /var/www/alerta/favicon.ico diff --git a/tasks/main.yml b/tasks/main.yml index ec58fa4cf06e88f906b7d5a0658911d298bafea8..84817dd833896ef79b868309b312619c5eb49d66 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -5,16 +5,20 @@ --- # file: roles/alerta/tasks/main.yml -- name: "Alerta Role" - set_fact: role_alerta_started=true - tags: 'always' +- name: Alerta Role + set_fact: + role_alerta_started: yes + tags: + - always - block: - import_tasks: alerta.yml - - name: 'Remember that this role had been run' - set_fact: role_alerta_completed=true - tags: 'always' + - name: Remember that this role had been run + set_fact: + role_alerta_completed: yes + tags: + - always - when: '"alerta" not in excluded_roles and role_alerta_completed is not defined' + when: not excluded_roles or "alerta" not in excluded_roles and role_alerta_completed is not defined diff --git a/templates/gitlab/alerta_gitlab.py b/templates/gitlab/alerta_gitlab.py index 4e6c1d505e2ebae8093cea114d64360a916f0c26..fe23a07b0d4c1e0fac2837e6c76824766712c2dc 100644 --- a/templates/gitlab/alerta_gitlab.py +++ b/templates/gitlab/alerta_gitlab.py @@ -48,7 +48,7 @@ class GitlabIssue(PluginBase): raw_data = alert.raw_data issue = project.issues.create({ 'title': alert.text[0:128], - 'description': '{}/alert/{}\n\nService: {}\n\nOrigin: {}\n\n```\n{}\n```\n'.format(ALERTA_URL, alert.id, alert.service, alert.origin, raw_data) + 'description': {}/alert/{}\n\nService: {}\n\nOrigin: {}\n\n```\n{}\n```\n.format(ALERTA_URL, alert.id, alert.service, alert.origin, raw_data) }) # type: gitlab.Issue alert.attributes['issue_iid'] = issue.id alert.attributes['gitlabUrl'] = '<a href="{}" target="_blank">Issue #{}</a>'.format(