【发布时间】:2020-02-25 20:44:46
【问题描述】:
尝试在 Ansible 中仅在 with_items 中的第一项上运行此任务。我无法更改 cluster_server_names 变量,因为它在其他地方使用。我是否需要一个单独的任务来注册一个只包含我想要的服务器名称的新变量,还是有其他可能的方法?
- name: "Provision public IP in dev"
uri:
url: "{{ api_url }}/servers/{{ item }}/publicIPAddresses"
headers:
Authorization: "REMOVED"
Content-Type: "application/json"
Accept: "application/json"
method: POST
body_format: json
status_code:
- 200
- 201
- 202
body:
ports: [{"protocol":"TCP","port":"80"}]
no_log: false
register: blueprint
run_once: true
with_items:
- "{{cluster_server_names |json_query(get_server_names)}}"
【问题讨论】: