kolla-ansible/ansible/roles/monasca/tasks/post_config.yml
Radosław Piliszek 7bd8805004 Fix Grafana datasource update
Grafana changed the error message wording.
Match on the shortest sane string to play it safe.

Change-Id: Ic175ebdb1da6ef66047309ff07bcbba98fc67008
Closes-Bug: #1881890
2020-06-15 11:34:30 +02:00

121 lines
4.8 KiB
YAML

---
- name: Wait for Monasca Grafana to load
become: true
kolla_toolbox:
module_name: uri
module_args:
url: "{{ internal_protocol }}://{{ kolla_internal_fqdn | put_address_in_context('url') }}:{{ monasca_grafana_server_port }}/login"
status_code: 200
register: result
until: result.get('status') == 200
retries: 10
delay: 2
run_once: true
- name: Define Monasca Grafana control plane organisation name
set_fact:
monasca_grafana_control_plane_org: "{{ monasca_control_plane_project }}@{{ default_project_domain_id }}"
- name: List Monasca Grafana organisations
become: true
kolla_toolbox:
module_name: uri
module_args:
method: GET
url: "{{ internal_protocol }}://{{ kolla_internal_fqdn | put_address_in_context('url') }}:{{ monasca_grafana_server_port }}/api/orgs"
user: '{{ monasca_grafana_admin_username }}'
password: '{{ monasca_grafana_admin_password }}'
return_content: true
force_basic_auth: true
run_once: True
register: monasca_grafana_orgs
- name: Create default control plane organisation if it doesn't exist
become: true
vars:
monasca_orgs_body:
name: '{{ monasca_grafana_control_plane_org }}'
kolla_toolbox:
module_name: uri
module_args:
method: POST
url: "{{ internal_protocol }}://{{ kolla_internal_fqdn | put_address_in_context('url') }}:{{ monasca_grafana_server_port }}/api/orgs"
user: '{{ monasca_grafana_admin_username }}'
password: '{{ monasca_grafana_admin_password }}'
body_format: json
body: "{{ monasca_orgs_body | to_json }}"
force_basic_auth: true
run_once: True
when: monasca_grafana_control_plane_org not in monasca_grafana_orgs.json|map(attribute='name')|unique
- name: Lookup Monasca Grafana control plane organisation ID
become: true
kolla_toolbox:
module_name: uri
module_args:
method: GET
url: "{{ internal_protocol }}://{{ kolla_internal_fqdn | put_address_in_context('url') }}:{{ monasca_grafana_server_port }}/api/orgs/name/{{ monasca_grafana_control_plane_org }}" # noqa 204
user: '{{ monasca_grafana_admin_username }}'
password: '{{ monasca_grafana_admin_password }}'
return_content: true
force_basic_auth: true
run_once: True
register: monasca_grafana_conf_org
- name: Add {{ monasca_grafana_admin_username }} user to control plane organisation
vars:
monasca_user_body:
loginOrEmail: '{{ monasca_grafana_admin_username }}'
role: Admin
become: true
kolla_toolbox:
module_name: uri
module_args:
method: POST
url: "{{ internal_protocol }}://{{ kolla_internal_fqdn | put_address_in_context('url') }}:{{ monasca_grafana_server_port }}/api/orgs/{{ monasca_grafana_conf_org.json.id }}/users" # noqa 204
user: '{{ monasca_grafana_admin_username }}'
password: '{{ monasca_grafana_admin_password }}'
body: "{{ monasca_user_body | to_json }}"
force_basic_auth: true
body_format: json
status_code: 200, 409
register: monasca_grafana_add_user_response
run_once: True
changed_when: monasca_grafana_add_user_response.status == 200
failed_when: monasca_grafana_add_user_response.status not in [200, 409] or
monasca_grafana_add_user_response.status == 409 and ("User is already" not in monasca_grafana_add_user_response.json.message|default(""))
- name: Switch Monasca Grafana to the control plane organisation
become: true
kolla_toolbox:
module_name: uri
module_args:
method: POST
url: "{{ internal_protocol }}://{{ kolla_internal_fqdn | put_address_in_context('url') }}:{{ monasca_grafana_server_port }}/api/user/using/{{ monasca_grafana_conf_org.json.id }}" # noqa 204
user: '{{ monasca_grafana_admin_username }}'
password: '{{ monasca_grafana_admin_password }}'
force_basic_auth: true
run_once: True
- name: Enable Monasca Grafana datasource for control plane organisation
become: true
kolla_toolbox:
module_name: uri
module_args:
url: "{{ internal_protocol }}://{{ kolla_internal_fqdn | put_address_in_context('url') }}:{{ monasca_grafana_server_port }}/api/datasources"
method: POST
user: "{{ monasca_grafana_admin_username }}"
password: "{{ monasca_grafana_admin_password }}"
body: "{{ item.value.data | to_json }}"
body_format: json
force_basic_auth: true
status_code: 200, 409
register: monasca_grafana_datasource_response
run_once: True
changed_when: monasca_grafana_datasource_response.status == 200
failed_when: monasca_grafana_datasource_response.status not in [200, 409] or
(monasca_grafana_datasource_response.status == 409 and
"name already exists" not in monasca_grafana_datasource_response.json.message|default(""))
with_dict: "{{ monasca_grafana_data_sources }}"
when: item.value.enabled | bool