如何使用json_modify.py更改JSON键名?
我有以下数组,我想把public_ip_address
改为public_ip_address_name
.
"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/cloud-shell-storage-centralindia/providers/Microsoft.Network/publicIPAddresses/Ubuntu-915-test",
"public_ip_allocation_method": "Dynamic"
}
],
下面是一个如何使用json_modify的示例,但我不确定如何更改键.
- json_modify:
data: "{{ azure_network_interface_info }}"
pointer: "/networkinterfaces/0/ip_configurations/0"
action: update
update: { "public_ip_address": "testing" }
register: azure_network_interface_info_modified
以下是azure_network_interface_info
个事实:
{
"hosts": {
"localhost": {
"_ansible_no_log": null,
"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": "cloud-shell-storage-centralindia",
"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/cloud-shell-storage-centralindia/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/cloud-shell-storage-centralindia/providers/Microsoft.Network/publicIPAddresses/Ubuntu-915-test",
"public_ip_allocation_method": null
}
],
"location": "eastus",
"mac_address": "00-0D-3A-8C-CF-8C",
"name": "Ubuntu915",
"provisioning_state": "Succeeded",
"resource_group": "cloud-shell-storage-centralindia",
"security_group": "/subscriptions/123456/resourceGroups/cloud-shell-storage-centralindia/providers/Microsoft.Network/networkSecurityGroups/testing_testing_temp_123",
"subnet": "default",
"tags": null,
"virtual_network": {
"name": "testing-vm_group-vnet",
"resource_group": "testing-vm_group"
}
}
]
}
},
"task": {
"duration": {
"end": "2022-07-25T16:39:01.551871Z",
"start": "2022-07-25T16:38:58.618111Z"
},
"id": "0242ac11-0002-08f0-de66-00000000000a",
"name": "Get facts for one network interface"
}
},