Home > front end >  Ansible - Member not found when using json_modify.py
Ansible - Member not found when using json_modify.py

Time:07-24

I'm trying to modify the json public_ip_allocation_method value using json_modify.py.

But I get the following error:

"msg": "member '' not found in {'name': 'Ubuntu915', 'private_ip_address': '10.0.0.5', 'private_ip_allocation_method': 'Dynamic', 'primary': True, 'load_balancer_backend_address_pools': None, 'application_gateway_backend_address_pools': None, 'public_ip_address': '/subscriptions/123456/resourceGroups/test-rg/providers/Microsoft.Network/publicIPAddresses/Ubuntu-915-test', 'public_ip_allocation_method': None, 'application_security_groups': None}" }

Playbook:

  - name: Get facts for one network interface
    azure_rm_networkinterface_info:
      resource_group: "{{ resource_group }}"
      name: "{{ azure_vm_network_interface }}"
    register: azure_network_interface_info    

  - name: "Network interface List"
    set_fact:
      mydict: {
               'public_ip_allocation_method': 'Dynamic', 
               }

  - debug:
      var: mydict

  - json_modify:
      data: "{{ azure_network_interface_info }}"
      pointer: "/networkinterfaces/0/ip_configurations/0/"
      action: update
      update "{{ mydict }}"
    register: result

JSON output:

            {
                "hosts": {
                    "localhost": {
                        "_ansible_no_log": false,
                        "action": "azure_rm_networkinterface_info",
                        "changed": false,
                        "invocation": {
                            "module_args": {
                                "ad_user": null,
                                "adfs_authority_url": null,
                                "api_profile": "latest",
                                "auth_source": "auto",
                                "cert_validation_mode": null,
                                "client_id": null,
                                "cloud_environment": "AzureCloud",
                                "log_mode": null,
                                "log_path": null,
                                "name": "Ubuntu915",
                                "password": null,
                                "profile": null,
                                "resource_group": "test-rg",
                                "secret": null,
                                "subscription_id": null,
                                "tags": null,
                                "tenant": null
                            }
                        },
                        "networkinterfaces": [
                            {
                                "dns_servers": [],
                                "dns_settings": {
                                    "applied_dns_servers": [],
                                    "dns_servers": [],
                                    "internal_dns_name_label": null,
                                    "internal_fqdn": null
                                },
                                "enable_accelerated_networking": false,
                                "enable_ip_forwarding": false,
                                "id": "/subscriptions/123456/resourceGroups/test-rg/providers/Microsoft.Network/networkInterfaces/Ubuntu915",
                                "ip_configurations": [
                                    {
                                        "application_gateway_backend_address_pools": null,
                                        "application_security_groups": null,
                                        "load_balancer_backend_address_pools": null,
                                        "name": "Ubuntu915",
                                        "primary": true,
                                        "private_ip_address": "10.0.0.5",
                                        "private_ip_allocation_method": "Dynamic",
                                        "public_ip_address": "/subscriptions/123456/resourceGroups/test-rg/providers/Microsoft.Network/publicIPAddresses/Ubuntu915-publicIp",
                                        "public_ip_allocation_method": null
                                    }
                                ],
                                "location": "eastus",
                                "mac_address": "00-0D-3A-8C-CF-8C",
                                "name": "Ubuntu915",
                                "provisioning_state": "Succeeded",
                                "resource_group": "test-rg",
                                "security_group": "/subscriptions/123456/resourceGroups/test-rg/providers/Microsoft.Network/networkSecurityGroups/fortify_testing_temp_123",
                                "subnet": "default",
                                "tags": null,
                                "virtual_network": {
                                    "name": "testing-vm_group-vnet",
                                    "resource_group": "testing-vm_group"
                                }
                            }
                        ]
                    }
                },

CodePudding user response:

following the documentation of jsonpointer,

you have to write:

pointer: "/networkinterfaces/0/ip_configurations/0"

and not

pointer: "/networkinterfaces/0/ip_configurations/0/"

  • Related