--- # tasks file for hcio - name: Create checks on the server ansible.builtin.uri: status_code: [200, 201] method: POST url: "{{ hcio_url }}/api/v3/checks/" headers: X-Api-Key: "{{ hcio_api_key }}" body_format: json body: > { "name": "{{ item.name }}", "slug": "{{ hcio_slug_prefix }}{{ item.slug }}", "tags": "{{ item.tags | join(' ') }}", "timeout": {{ timeout }}, "grace": {{ item.grace if item.grace is defined else grace }}, "channels": "{{ channels }}", "unique": ["name"] } when: uuid | length <= 0 changed_when: true register: created loop: "{{ hcio_checks }}" loop_control: label: "{{ item.name }}" notify: - Write UUID in local facts - Reload local facts vars: timeout: "{{ (item.timeout | int) + 30 }}" grace: "{{ (item.timeout | int) * 3 }}" channels: "{{ item.channels | join(',') }}" uuid: "{{ ansible_local.get('chaos', {}).get('role_hcio', {}).get(item.slug, {}) }}" - name: Flush handlers ansible.builtin.meta: flush_handlers - name: Update checks on the server ansible.builtin.uri: status_code: [200, 201] method: POST url: "{{ hcio_url }}/api/v3/checks/{{ uuid }}" headers: X-Api-Key: "{{ hcio_api_key }}" body_format: json body: > { "slug": "{{ hcio_slug_prefix }}{{ item.slug }}", "tags": "{{ item.tags | join(' ') }}", "timeout": {{ timeout }}, "grace": {{ item.grace if item.grace is defined else grace }}, "channels": "{{ channels }}", } when: uuid | length > 0 loop: "{{ hcio_checks }}" loop_control: label: "{{ item.name }}" vars: timeout: "{{ (item.timeout | int) + 30 }}" grace: "{{ (item.timeout | int) * 3 }}" channels: "{{ item.channels | join(',') }}" uuid: "{{ ansible_local.get('chaos', {}).get('role_hcio', {}).get(item.slug, {}) }}" - name: Deploy scripts from this role ansible.builtin.copy: src: "{{ item }}" dest: "{{ hcio_path }}/{{ filename }}" owner: root group: root mode: u=rwx,g=rx,o=rx become: true loop: "{{ lookup('ansible.builtin.fileglob', path + '/*.j2', wantlist=True) }}" vars: path: "{{ role_path }}/templates/scripts" filename: "{{ item | basename | replace('.j2', '') }}" - name: Deploy scripts from playbook ansible.builtin.copy: src: "{{ item }}" dest: "{{ hcio_path }}/{{ filename }}" owner: root group: root mode: u=rwx,g=rx,o=rx become: true loop: "{{ lookup('ansible.builtin.fileglob', path + '/*.j2', wantlist=True) }}" vars: path: "{{ playbook_dir }}/templates/role_hcio" filename: "{{ item | basename | replace('.j2', '') }}" - name: Deploy checks on the instance ansible.builtin.template: owner: root group: root mode: u=rw,g=r,o=r src: service.j2 dest: /etc/systemd/system/{{ filename }}.service when: item.cmd is defined become: true loop: "{{ hcio_checks }}" loop_control: label: "{{ item.name }}" vars: filename: "hcio@{{ item.slug }}" uuid: "{{ ansible_local.get('chaos', {}).get('role_hcio', {}).get(item.slug, {}) }}" - name: Deploy schedules on the instance ansible.builtin.template: owner: root group: root mode: u=rw,g=r,o=r src: timer.j2 dest: /etc/systemd/system/{{ filename }}.timer when: item.cmd is defined become: true loop: "{{ hcio_checks }}" loop_control: label: "{{ item.name }}" vars: filename: "hcio@{{ item.slug }}" - name: Enable schedules ansible.builtin.systemd: enabled: true daemon_reload: true state: started name: "{{ filename }}.timer" when: item.cmd is defined become: true loop: "{{ hcio_checks }}" loop_control: label: "{{ item.name }}" vars: filename: "hcio@{{ item.slug }}"