Ansible - 修改注册变量

Ansible - 修改注册变量

我怎样才能修改已注册的变量?

例如,我azure_network_interface_info.networkinterfaces[0].ip_configurationspublic_ip_allocation_method将其更改为StaticDynamic。然后ip_configurations在修改数组后在其他地方使用该数组。

  - 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  

注册变量的输出:

                        "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_address_version": "IPv4",
                                "private_ip_allocation_method": "Dynamic",
                                "public_ip_address": "/subscriptions/123456789/resourceGroups/test-resource-group/providers/Microsoft.Network/publicIPAddresses/Ubuntu-915-test",
                                "public_ip_address_name": "/subscriptions/123456789/resourceGroups/test-resource-group/providers/Microsoft.Network/publicIPAddresses/Ubuntu-915-test",
                                "public_ip_allocation_method": null
                            }
                        ],

答案1

虽然无法在某些地方更新变量,但是你可以使用update_fact模块 – 更新当前设置的事实创建其他数据结构,例如

updated.azure_network_interface_info

并使用那个。看来其中一个文档示例恰好涵盖了您的用例。

文档

更多问答

相关内容