From 5db9eab04223dd3e974e39490a84c506805b8644 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Fri, 21 Feb 2020 10:08:10 +0000 Subject: [PATCH] Fix invalid JSON body in Elasticsearch API requests The kibana, elasticsearch and monasca roles all use the uri module to perform Elasticsearch configuration tasks via its API. The body of the request should be JSON formatted, but these tasks now fail because it is not. The following error is seen: TASK [monasca : Create default control plane organisation if it doesn't exist] invalid character '\\'' looking for beginning of object key string The 'JSON' body in this case was: {'name': 'monasca_control_plane@default'} This was probably caused by the recent change to execute these tasks in the kolla_toolbox container, but may also be caused by an Ansible version bump (or something else). This change fixes the issue by ensuring that the body is JSON-encoded in all cases. Change-Id: I7acc097381dd9a4af4e014525c1c88213abbde93 Closes-Bug: #1864177 --- ansible/roles/elasticsearch/tasks/upgrade.yml | 4 +++- ansible/roles/kibana/tasks/post_config.yml | 6 ++++-- ansible/roles/monasca/tasks/post_config.yml | 14 +++++++++----- .../notes/uri-json-body-46891dd478d2ad37.yaml | 7 +++++++ 4 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 releasenotes/notes/uri-json-body-46891dd478d2ad37.yaml diff --git a/ansible/roles/elasticsearch/tasks/upgrade.yml b/ansible/roles/elasticsearch/tasks/upgrade.yml index a15ca5026e..f7203c16e5 100644 --- a/ansible/roles/elasticsearch/tasks/upgrade.yml +++ b/ansible/roles/elasticsearch/tasks/upgrade.yml @@ -3,6 +3,8 @@ # https://www.elastic.co/guide/en/elasticsearch/reference/5.6/restart-upgrade.html - name: Disable shard allocation become: true + vars: + elasticsearch_shard_body: {"transient": {"cluster.routing.allocation.enable": "none"}} kolla_toolbox: module_name: uri module_args: @@ -10,7 +12,7 @@ method: PUT status_code: 200 return_content: yes - body: {"transient": {"cluster.routing.allocation.enable": "none"}} + body: "{{ elasticsearch_shard_body | to_json }}" body_format: json delegate_to: "{{ groups['elasticsearch'][0] }}" run_once: true diff --git a/ansible/roles/kibana/tasks/post_config.yml b/ansible/roles/kibana/tasks/post_config.yml index d53584f90a..1fa51673c9 100644 --- a/ansible/roles/kibana/tasks/post_config.yml +++ b/ansible/roles/kibana/tasks/post_config.yml @@ -37,14 +37,16 @@ run_once: true - name: Change kibana config to set index as defaultIndex + vars: + kibana_default_index_body: + defaultIndex: "{{ kibana_default_index_pattern }}" become: true kolla_toolbox: module_name: uri module_args: url: "{{ internal_protocol }}://{{ kolla_internal_vip_address | put_address_in_context('url') }}:{{ elasticsearch_port }}/.kibana/config/*" method: PUT - body: - defaultIndex: "{{ kibana_default_index_pattern }}" + body: "{{ kibana_default_index_body | to_json }}" body_format: json status_code: 200, 201 run_once: true diff --git a/ansible/roles/monasca/tasks/post_config.yml b/ansible/roles/monasca/tasks/post_config.yml index de3f0170d9..a273c49bd2 100644 --- a/ansible/roles/monasca/tasks/post_config.yml +++ b/ansible/roles/monasca/tasks/post_config.yml @@ -32,6 +32,9 @@ - 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: @@ -40,8 +43,7 @@ user: '{{ monasca_grafana_admin_username }}' password: '{{ monasca_grafana_admin_password }}' body_format: json - body: - name: '{{ monasca_grafana_control_plane_org }}' + 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 @@ -61,6 +63,10 @@ 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 @@ -69,9 +75,7 @@ url: "{{ internal_protocol }}://{{ kolla_internal_vip_address | put_address_in_context('url') }}:{{ monasca_grafana_server_port }}/api/orgs/{{ monasca_grafana_conf_org.json.id }}/users" user: '{{ monasca_grafana_admin_username }}' password: '{{ monasca_grafana_admin_password }}' - body: - loginOrEmail: '{{ monasca_grafana_admin_username }}' - role: Admin + body: "{{ monasca_user_body | to_json }}" force_basic_auth: true body_format: json status_code: 200, 409 diff --git a/releasenotes/notes/uri-json-body-46891dd478d2ad37.yaml b/releasenotes/notes/uri-json-body-46891dd478d2ad37.yaml new file mode 100644 index 0000000000..e938587d40 --- /dev/null +++ b/releasenotes/notes/uri-json-body-46891dd478d2ad37.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Fixes an issue where Elasticsearch API requests made during Kibana, + Elasticsearch and Monasca deployment could have an invalid body. See `bug + 1864177 `_ for + details.