0

Ansible Azure module returns the data in a weird format Double single quoted characters.

''network_interface_names'': [''Ubuntu915'']

As a result I can't use this anywhere to filter other resources.

Any idea what can be done to fix this or make it json?

  - name: Get facts by name
    azure_rm_virtualmachine_info:
      resource_group: "{{ resource_group }}"
      name: "{{ vm_name }}"
    register: azure_vm_info

  - name: "Network interface List"
    set_fact:
      azure_vm_network_interface: "{{ [ azure_vm_info.vms[0].network_interface_names  ] }}"

  - name: Print Azure VM Info
    debug:
      msg: "Azure VM INFO: {{ azure_vm_info.vms[0].network_interface_names }}"

Output:

   TASK [Print Azure VM Info] ****************************************************************************************************************************************************************************************************************************************************
   ok: [localhost] =>
   msg: 'Azure VM INFO: [''Ubuntu915'']'
user630702
  • 495
  • 10
  • 32

2 Answers2

0

Figured it out.

In ansible.cfg I had set stdout_callback = yaml. changing it json fixed the issue

user630702
  • 495
  • 10
  • 32
0

ansible-playbook standard output is for human consumption, not for machine parsing.

Typically you would take task outputs from register: variables, and send them through filters, use in expressions, or otherwise process them.

Or, ansible-runner has a well defined output format. It exists to power AWX/Tower.

John Mahowald
  • 32,050
  • 2
  • 19
  • 34