kolla-ansible/ansible/roles/monasca/tasks/post_config.yml
Rafael Weingärtner f425c0678f Standardize use and construction of endpoint URLs
The goal for this push request is to normalize the construction and use
 of internal, external, and admin URLs. While extending Kolla-ansible
 to enable a more flexible method to manage external URLs, we noticed
 that the same URL was constructed multiple times in different parts
 of the code. This can make it difficult for people that want to work
 with these URLs and create inconsistencies in a large code base with
 time. Therefore, we are proposing here the use of
 "single Kolla-ansible variable" per endpoint URL, which facilitates
 for people that are interested in overriding/extending these URLs.

As an example, we extended Kolla-ansible to facilitate the "override"
of public (external) URLs with the following standard
"<component/serviceName>.<companyBaseUrl>".
Therefore, the "NAT/redirect" in the SSL termination system (HAproxy,
HTTPD or some other) is done via the service name, and not by the port.
This allows operators to easily and automatically create more friendly
 URL names. To develop this feature, we first applied this patch that
 we are sending now to the community. We did that to reduce the surface
  of changes in Kolla-ansible.

Another example is the integration of Kolla-ansible and Consul, which
we also implemented internally, and also requires URLs changes.
Therefore, this PR is essential to reduce code duplicity, and to
facility users/developers to work/customize the services URLs.

Change-Id: I73d483e01476e779a5155b2e18dd5ea25f514e93
Signed-off-by: Rafael Weingärtner <rafael@apache.org>
2020-08-19 07:22:17 +00:00

121 lines
4.3 KiB
YAML

---
- name: Wait for Monasca Grafana to load
become: true
kolla_toolbox:
module_name: uri
module_args:
url: "{{ monasca_grafana_internal_endpoint }}/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: "{{ monasca_grafana_internal_endpoint }}/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: "{{ monasca_grafana_internal_endpoint }}/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: "{{ monasca_grafana_internal_endpoint }}/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: "{{ monasca_grafana_internal_endpoint }}/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: "{{ monasca_grafana_internal_endpoint }}/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: "{{ monasca_grafana_internal_endpoint }}/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