Post Request using uri module to update the parameter flags/values

15 views
Skip to first unread message

abhijith...@gmail.com

unread,
Feb 26, 2019, 9:05:48 PM2/26/19
to Ansible Project
Hello There,

I have the below GET response for a feature API request. I would like to update the values for the corresponding parameters as follows in the json object:

"paramValue": 15

"configState": "ENABLE"

GET Response output: 

TASK [debug] *********************************************************************************************************************
ok: [localhost] => {
    "msg": {
        "changed": false,
        "connection": "close",
        "content_length": "126",
        "content_type": "application/json",
        "cookies": {},
        "date": "Wed, 27 Feb 2019 01:47:59 GMT",
        "failed": false,
        "json": {
            "configClass": "MASTER",
            "configState": "DISABLE",
            "id": "FEATURE-BIT",
            "instanceId": 0,
            "paramValue": 0,
        },
        "msg": "OK (126 bytes)",
        "redirected": false,
        "status": 200,
    }
}

I am not sure of the syntax, how to update the values/flags in the json object and send POST request using URI module. Please advice ?

AD

unread,
Feb 26, 2019, 9:26:25 PM2/26/19
to Ansible Project
Here is the snipped from the playbook for "GET" request task: 

    - name: Enable feature bit/parameters
      uri:
        url: https://<API REQUEST URL >
        method: GET
        return_content: yes
        status_code: 200
        headers:
          Content-Type: application/json
          Cookie: "{{ login.set_cookie.split(';')[0] }}"
        body_format: json
      register: api_result
      tags: enable_stay_sec
      changed_when: false
      failed_when: api_result.status != 200

    - debug:
        msg: "{{ api_result }}"
Reply all
Reply to author
Forward
0 new messages