我在解釋with_items變量的Ansible腳本模塊中遇到問題。Ansible腳本模塊不解釋變量
vsa_deploy_config /任務/ main.yml:
- name: Create VSA scripts for center
template:
src: vsa_deploy.ps1.j2
dest: "/opt/ansible/roles/vsa_deploy_config/files/{{ item.vsa_hostname }}.ps1"
when: target == "local"
with_items:
- "{{ vsa_center }}"
- name: Deploy VSAs on Center
script: "files/{{ item.vsa_hostname }}.ps1"
register: out
when: target == "win_center"
- debug: var=out
with_items:
- "{{ vsa_center }}"
vsa_deploy_config /瓦爾/ main.yml:
---
vsa_center:
- vcsa_hostname: 10.10.10.74
vcsa_username: [email protected]
vcsa_password: password
vcsa_datacenter: DataCenter1
vsa_rdm_lun: 02000000006006bf1d58d25a1020d292f8fcfb22b3554353432d4d
vsa_hostname: sm01-ct01
vsa_mgmt_ip: 10.10.10.75
vsa_mgmt_netmask: 255.255.255.192
vsa_mgmt_gw: 10.10.10.65
vsa_mgmt_ns: 10.10.10.92
vsa_mgmt_pg: SC-MGMT
vsa_mgmt_moref: Network:network-13
vsa_iscsi_ip: 192.168.2.1
vsa_iscsi_netmask: 255.255.255.0
vsa_iscsi_pg: ISCSI
vsa_iscsi_moref: Network:network-22
vsa_mirror_ip: 192.168.5.1
vsa_mirror_netmask: 255.255.255.0
vsa_mirror_pg: Mirror
vsa_mirror_moref: Network:network-23
esxi_hostname: 10.10.10.72
esxi_datastore: DS-01
- vcsa_hostname: 10.10.10.74
vcsa_username: [email protected]
vcsa_password: password
vcsa_datacenter: DataCenter1
vsa_rdm_lun: 02000000006006bf1d58d25dd0210bb356a78344e5554353432d4d
vsa_hostname: sm02-ct01
vsa_mgmt_ip: 10.10.10.76
vsa_mgmt_netmask: 255.255.255.192
vsa_mgmt_gw: 10.10.10.65
vsa_mgmt_ns: 10.10.10.92
vsa_mgmt_pg: SC-MGMT
vsa_mgmt_moref: Network:network-13
vsa_iscsi_ip: 192.168.2.2
vsa_iscsi_netmask: 255.255.255.0
vsa_iscsi_pg: ISCSI
vsa_iscsi_moref: Network:network-22
vsa_mirror_ip: 192.168.5.2
vsa_mirror_netmask: 255.255.255.0
vsa_mirror_pg: Mirror
vsa_mirror_moref: Network:network-23
esxi_hostname: 10.2.120.73
esxi_datastore: DS-02
當我運行的劇本,我得到以下錯誤:
任務[vsa_deploy_config:在中心部署VSA] ********* ************************************************** ******************** 致命:[auto-win1.lab.com]:FAILED! => {「failed」:true,「msg」:「字段'args'有一個無效值,其中包含一個未定義的變量,錯誤是:'item'未定義\ n \ n錯誤似乎是已經在'/opt/ansible/roles/vsa_deploy_config/tasks/main.yml'中:第10行第3列,但可能在文件中的其他位置取決於確切的語法問題。\ n \ n違規行似乎是:\ n \ n \ n名稱:在中心部署VSA \ n「} 要重試,請使用:--limit @/opt/ansible/powershell.retry
使用模板模塊正確解釋item.vsa_hostname變量,但腳本模塊沒有。腳本模塊是否無法使用with_items?