API Call output via Ansible URI Module Not Getting the Complete Output

28 views
Skip to first unread message

Pradeep Antil

unread,
Jan 6, 2020, 3:33:50 AM1/6/20
to Ansible Project
Hi Team,

I have a small playbook which connects to InfoBlox Server and collects useful data via API and then save API commands out to variable and later redirecting variable output to a log file.

Issue is that Variable is not getting all output but it captures only fraction of output. Any idea and suggestion how to capture complete output of API call and save it in log file in formatted way , just like Jason

Below is playbook:

---
- hosts: localhost
  connection: local
  gather_facts: no
    vars_files:
    - infoblox_pass.yml
  tasks:
    - name: Command to get Infoblox data
      uri:
        url: "https://x.x.x.x/wapi/v2.9/member?_return_fields%2B=node_info&_return_as_object=1"
        method: GET
        user: admin
        password: "xxxxxxx"
        validate_certs: no
      register: pool_members_resource

    - name: Command to get DNS & NTP Service Status of pool members
      uri:
        url: "https://x.x.x.x/wapi/v2.9/member?_return_fields%2B=service_status&_return_as_object=1"
        method: GET
        user: admin
        password: "xxxxxxxx"
        validate_certs: no
      register: pool_members_service_status

#    - debug:
#        msg: "{{ pool_members_service_status }}"
    - lineinfile:
        path: "/root/logs/infoblox-{{ dates }}.log"
        create: yes
        line: "{{ item }}"
      with_items:
        - "{{ pool_members_resource }}"
        - "{{ pool_members_service_status }}"

#- hosts: "{{ nagios_node }}"
#  gather_facts: false
#  tasks:
#    - copy:
#        src: "/root/logs/infoblox-{{ dates }}.log"
#        dest: /var/tmp/nagios_logs/infoblox/
#        owner: nagios
#        group: nagios
#
...

Dick Visser

unread,
Jan 6, 2020, 4:25:53 AM1/6/20
to ansible...@googlegroups.com
Have a look at the return_content parameter of the uri module
> --
> 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 ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/31ae197e-5088-4cab-9c16-c08edf07123a%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Pradeep Antil

unread,
Jan 6, 2020, 5:40:54 AM1/6/20
to ansible...@googlegroups.com
Thank You Very Much, it resolves my output capture issue.

Now content is saved in log file with the following format, is there any way to format that data while saving it a file. As you can see in the output below, in place of new line \n is printed.


{'content': '{\n    "result": [\n        {\n            "_ref": "member/bxxxxxxxxxxxxxx, \n            "config_addr_type": "IPV4", \n            "host_name": "xxxxxxxxxxxxxxxxxxxxxx", \n            "node_info": [\n                {\n                    "ha_status": "NOT_CONFIGURED", \n                    "hwid": "892A5BA7A1CB4AA9BEAB99A3ECC81116", \n                    "hwmodel": "", \n                    "hwplatform": "KVM", \n                    "hwtype": "IB-V825", \n                    "lan2_physical_setting": {\n                        "auto_port_setting_enabled": true\n                    }, \n                    "lan_ha_port_setting": {\n                        "ha_port_setting": {\n                            "auto_port_setting_enabled": true, \n                            "speed": "10"\n                        }, \n                        "lan_port_setting": {\n                            "auto_port_setting_enabled": true\n                        }\n                    }, \n                    "mgmt_network_setting": {\n                        "address": "xxxxxxx", \n                        "gateway": "xxxxxxxx", \n                        "subnet_mask": "255.255.255.248"\n                    }, \n                    "mgmt_physical_setting": {\n                        "auto_port_setting_enabled": true\n                    }, \n                    "paid_nios": false, \n                    "physical_oid": "0", \n                    "service_status": [\n                        {\n                            "description": "Running", \n                            "service": "NODE_STATUS", \n                            "status": "WORKING"\n                        }, \n                        {\n                            "description": "2% - Primary drive usage is OK.", \n                            "service": "DISK_USAGE", \n                            "status": "WORKING"\n                        }, \n                        {\n                            "description": "10.250.169.140", \n                            "service": "ENET_LAN", \n                            "status": "WORKING"\n                        }, \n                        {\n                            "description": "xxxxxxx", \n                            "service": "ENET_LAN2", \n                            "status": "WORKING"\n                        }, \n                        {\n                            "description": "10.250.169.132", \n                            "service": "ENET_MGMT", \n                            "status": "WORKING"\n                        }, \n                        {\n                            "description": "3% - Data



Vivek Kothawale

unread,
Jan 6, 2020, 5:46:31 AM1/6/20
to ansible...@googlegroups.com
Hi pardeep,

You can use filter module of ansible to get ouput in from of yaml or json
  

Best regards,
Vivek

Pradeep Antil

unread,
Jan 6, 2020, 6:24:50 AM1/6/20
to ansible...@googlegroups.com
Thanks Vivek, your suggestion was very helpful and it resolves formatting issue

Reply all
Reply to author
Forward
0 new messages