【发布时间】:2019-08-07 12:22:12
【问题描述】:
我正在尝试使用 ansible hcloud 模块。 我需要使用我创建的服务器的 IP 设置一个事实列表。
第一个服务器很简单,因为它总是只有一个:
创建空列表:
- set_fact:
ips: []
然后创建服务器并将服务器IP添加到列表中:
- set_fact:
ips:
- "{{ ips + [ a3srv_fact.hcloud_server.ipv4_address ] }}"
下一个块有一个循环,因此寄存器给了我这个:
"hc_fact": {
"changed": false,
"msg": "All items completed",
"results": [
{
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"hcloud_server": {
"backup_window": "None",
"datacenter": "nbg1-dc3",
"id": "3083849",
"image": "centos-7",
"ipv4_address": "116.203.204.49",
"ipv6": "2a01:4f8:c2c:ade4::/64",
"labels": {},
"location": "nbg1",
"name": "a3hc1",
"rescue_enabled": false,
"server_type": "cx11",
"status": "running"
},
"invocation": {
"module_args": {
"api_token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"backups": false,
"datacenter": null,
"endpoint": "https://api.hetzner.cloud/v1",
"force_upgrade": false,
"id": null,
"image": "centos-7",
"labels": null,
"location": null,
"name": "a3hc1",
"server_type": "cx11",
"ssh_keys": null,
"state": "present",
"upgrade_disk": false,
"user_data": null,
"volumes": null
}
},
"item": "hc1"
},
{
"ansible_loop_var": "item",
"changed": false,
"failed": false,
"hcloud_server": {
"backup_window": "None",
"datacenter": "nbg1-dc3",
"id": "3083921",
"image": "centos-7",
"ipv4_address": "116.203.204.136",
"ipv6": "2a01:4f8:c2c:ae25::/64",
"labels": {},
"location": "nbg1",
"name": "a3hc2",
"rescue_enabled": false,
"server_type": "cx11",
"status": "running"
},
"invocation": {
"module_args": {
"api_token": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"backups": false,
"datacenter": null,
"endpoint": "https://api.hetzner.cloud/v1",
"force_upgrade": false,
"id": null,
"image": "centos-7",
"labels": null,
"location": null,
"name": "a3hc2",
"server_type": "cx11",
"ssh_keys": null,
"state": "present",
"upgrade_disk": false,
"user_data": null,
"volumes": null
}
},
"item": "hc2"
}
]
}
结果块可以有 1 个或多个部分,有两个。
我需要将每个 ipv4_address 添加到现有的事实列表中。
我很确定 yml 语法有一个简单的方法,但我就是不明白。
【问题讨论】: