以下是我的任務代碼:
- name: Add calculation nodes of different groups to the list
set_fact:
list_of_all_calculate_node: "{{ list_of_all_calculate_node | default([]) + ['random_calculate_host' + ('{{ item }}' | string ) ] }}"
loop: "{{ range(1,5) }}"
delegate_to: "localhost"
run_once: true
- name: Print list_of_all_calculate_node
debug:
var: "{{ item }}"
loop: "{{ list_of_all_calculate_node }}"
錯誤類型:致命
TASK [Print list_of_all_calculate_node]
fatal: [*.*.*.*]: FAILED! => {"msg": "['random_calculate_host2', 'random_calculate_host3', 'random_calculate_host4', 'random_calculate_host{{ item }}']: 'item' is undefined"}
預期的輸出應該是:['random_calculate_host1','random_calculate_host2', 'random_calculate_host3', 'random_calculate_host4']
在Ansible中,大括號
{{ }}
不能嵌套。修正語法,例如。gives
您不必迭代范圍。e、 下面的任務給出了相同的結果