Ok, I have found a solution.
First of all, for some bug in Ambari I have to use raw body format and no
json.
So I have changed the body_format to json and appended "Content-Type":
"text/plain" to the headers parameter.
Now my headers parameter looks like:
headers: '{"X-Requested-By":"ambari", "Content-Type":"text/plain"}'
Now everything works properly.
Hi all!
>
> This is my task that works:
> - name: Stop services on ambari
> uri:
> url: http://{{ inventory_hostname }}:8080/api/v1/clusters/{{
> hostvars[inventory_hostname].cluster_name }}/services/{{ service }}
> method: PUT
> force_basic_auth: yes
> user: "{{ ambari_admin_user }}"
> password: "{{ ambari_admin_password }}"
> headers: '{"X-Requested-By":"ambari"}'
> body: "{\"RequestInfo\":{ \"context\":\"Stop services via
> REST\"},\"ServiceInfo\":{\"state\":\"INSTALLED\"}}"
> status_code: 200,201,202
> body_format: raw
> timeout: 120
> return_content: yes
> register: returned_from_cluster
> when: "'AMBARI-SERVER' in group_names"
>
> I want to change the Stop services via REST part to Stop {{ service }}
> via REST.
> But the playbook fault with:
> "msg": "Status code was -1 and not [200, 201, 202]: An unknown error
> occurred: must be string or buffer, not dict"
>
> I tried to run the playbook with -vvv and saw the diffenence.
>
> This one without variable:
> "body": "{\\"RequestInfo\\":{ \\"context\\":\\"Stop services via REST\\
> "},\\"ServiceInfo\\":{\\"state\\":\\"INSTALLED\\"}}"
>
> And this one with variable:
> "body": {"RequestInfo": {"context": "Stop NIFI_REGISTRY via REST"},
> "ServiceInfo": {"state": "INSTALLED"}}
>
> How can I avoid this evaluation?
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/5922a4e0-c631-47ee-bc80-e0f8eb6be2ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.