I am trying to send a JSON payload using uri module through body parameter. 
The variables {{ network-name }} and and {{ IP1 }} are imported from 
config.yml. 

I have defined body in vars. The json code which I am trying to print is 
getting created properly using (debug: var={{ body | to_json}}). But, the 
output which I am redirecting to the dest file is showing errors. What 
could be the reason that the JSON payload is not getting sent at the 
destination url.


Here's the ansible playbook:



---
- hosts: localhost
  connection: local
  vars_files:
    - config.yml
  vars:
    body:
      id: 100
      network: 
        name: "{{ network-name }}"
        net_list:
          - link_id: 1
          - type: abc
      vlan: "10"
      profile: switch

  tasks:
    - debug: var="{{ body | to_json }}"
    - name: Run POST command
      uri:
        url: "https://{{ IP1 }}/url/to/dest 
<https://%7b%7b%20MP_FIX_IP%20%7d%7d/api/v1/host-switch-profiles>"
        method: POST
        body: "{{ body | to_json }}"
        user: "abc"
        password: "xyz"
        HEADER_Content-Type: "application/json"
        force_basic_auth: yes
        return_content: yes
        dest: /url/to/dest/file
       

-- 
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/85d514c4-68a4-4ab1-8d1d-3d9f9300abc6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to