You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hetzner-ansible/roles/kibana/tasks/_configure_spaces.yml

111 lines
3.0 KiB
YAML

---
- set_fact:
api_path: '/api/spaces/space'
space_exists: False
elastic_space_cleaned: {}
- name: "Get all spaces in elasticsearch"
delegate_to: localhost
uri:
url: "https://{{ api_endpoint }}{{ api_path }}"
method: GET
status_code: [200]
user: "{{ elastic_admin_username_vault }}"
password: "{{ elastic_admin_password_vault }}"
force_basic_auth: yes
register: all_spaces
become: false
- set_fact:
lookup_space_object: "{{ all_spaces.json | community.general.json_query(spaces_query) }}"
vars:
spaces_query: "[?name=='{{ elastic_space.name }}']"
- set_fact:
space_exists: True
when:
- lookup_space_object | length > 0
- set_fact:
elastic_space_cleaned: "{{ elastic_space_cleaned | combine({item.key: item.value}) }}"
with_dict: "{{ elastic_space }}"
when:
- item.key not in ['elastic_state']
- debug:
msg: "{{ lookup_space_object | to_json }}"
- name: "Create space <<{{ elastic_space.name }}>>"
delegate_to: localhost
uri:
url: "https://{{ api_endpoint }}{{ api_path }}"
method: POST
status_code: [200]
user: "{{ elastic_admin_username_vault }}"
password: "{{ elastic_admin_password_vault }}"
force_basic_auth: yes
headers:
Content-Type: application/json
kbn-xsrf: true
body_format: json
body: '{{ elastic_space_cleaned | to_json }}'
become: false
when:
- not space_exists
- elastic_space.elastic_state == 'present'
- name: "Update space <<{{ elastic_space.name }}>>"
delegate_to: localhost
uri:
url: "https://{{ api_endpoint }}{{ api_path }}/{{ elastic_space.name }}"
method: PUT
status_code: [200]
user: "{{ elastic_admin_username_vault }}"
password: "{{ elastic_admin_password_vault }}"
force_basic_auth: yes
headers:
Content-Type: application/json
kbn-xsrf: true
body_format: json
body: '{{ elastic_space_cleaned | to_json }}'
become: false
when:
- space_exists
- elastic_space.elastic_state == 'present'
- name: "Update space advanced settings <<{{ elastic_space.name }}>>"
delegate_to: localhost
uri:
url: "https://{{ api_endpoint }}/s/{{ elastic_space.name }}/api/kibana/settings"
method: POST
status_code: [200]
user: "{{ elastic_admin_username_vault }}"
password: "{{ elastic_admin_password_vault }}"
force_basic_auth: yes
headers:
Content-Type: application/json
kbn-xsrf: true
body_format: json
body: '{{ kibana_advanced_settings | to_json }}'
become: false
when:
- space_exists
- elastic_space.elastic_state == 'present'
- name: "DELETE space <<{{ elastic_space.name }}>>"
delegate_to: localhost
uri:
url: "https://{{ api_endpoint }}{{ api_path }}/{{ elastic_space.name }}"
method: DELETE
status_code: [204]
user: "{{ elastic_admin_username_vault }}"
password: "{{ elastic_admin_password_vault }}"
force_basic_auth: yes
headers:
Content-Type: application/json
kbn-xsrf: true
become: false
when:
- space_exists
- elastic_space.elastic_state == 'absent'