尝试仅在 with_items 中的第一项上在 Ansible 中运行此任务。我无法更改 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)}}"