尝试在Ansible中仅对with_items中的第一个项运行此任务。我无法更改cluster_server_name变量,因为它在其他地方使用。我需要一个单独的任务来注册一个只包含我想要的服务器名称的新变量吗?或者还有其他方法吗?
- 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)}}"
恐怕我没有办法对此进行测试,但请尝试first
过滤器:
- name: "Provision public IP in dev"
uri:
url: "{{ api_url }}/servers/{{ server }}/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
vars:
server: "{{cluster_server_names | json_query(get_server_names) | first }}"