feat: Create role
This commit is contained in:
134
tasks/checks.yml
Normal file
134
tasks/checks.yml
Normal file
@@ -0,0 +1,134 @@
|
||||
---
|
||||
# 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": {{ (item.timeout | int) + 30 }},
|
||||
"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:
|
||||
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: |
|
||||
{
|
||||
"name": "{{ item.name }}",
|
||||
"slug": "{{ hcio_slug_prefix }}{{ item.slug }}",
|
||||
"tags": "{{ item.tags | join(' ') }}",
|
||||
"timeout": {{ (item.timeout | int) + 30 }},
|
||||
"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:
|
||||
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 }}"
|
29
tasks/main.yml
Normal file
29
tasks/main.yml
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
# tasks file for hcio
|
||||
|
||||
- name: Install prerequisites
|
||||
ansible.builtin.apt:
|
||||
name: "{{ hcio_prerequisites }}"
|
||||
become: true
|
||||
|
||||
- name: Create directory to store scripts
|
||||
ansible.builtin.file:
|
||||
path: "{{ hcio_path }}"
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: u=rwX,g=rX,o=
|
||||
become: true
|
||||
|
||||
- name: Build the checks list
|
||||
ansible.builtin.set_fact:
|
||||
hcio_checks: "{{ hcio_checks + specific }}"
|
||||
when: specific | length > 0
|
||||
loop: "{{ lookup('ansible.builtin.varnames', '^hcio_checks_.+', wantlist=True) }}"
|
||||
vars:
|
||||
specific: "{{ lookup('ansible.builtin.vars', item, default='') }}"
|
||||
|
||||
- name: Import checks deployment tasks
|
||||
ansible.builtin.include_tasks:
|
||||
file: checks.yml
|
||||
when: hcio_checks | length > 0
|
Reference in New Issue
Block a user