按以下方法尝试时出现以下错误:
“ msg”:“(vmware_vm_vm_drs_rule)模块不支持的参数:委托_to支持的参数包括:affinity_rule,cluster_name,drs_rule_name,已启用,主机名,强制性,密码,端口,proxy_host,proxy_port,状态,用户名,validate_certs,vms”。
我不希望我的模块在final_list为空或少于一个对象时执行。只有当它在final_list中超过2个对象时,我才希望它执行。有人可以帮助我改善病情
"ansible_facts": {"final_list": [ "NPSY7ADFS01"]}
"ansible_facts": {"final_list": []}
- name: Create DRS Anti Affinity Rule for VM-VM
vmware_vm_vm_drs_rule:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
cluster_name: "{{ datacenter_name }}-{{ cluster_name }}"
validate_certs: no
vms: "{{ final_list }}"
drs_rule_name: "{{ rule_name }}"
enabled: True
mandatory: True
affinity_rule: "{{ action_type }}"
delegate_to: localhost
register: rule_creation
when: final_list is defined
答案 0 :(得分:2)
Q:”(vmware_vm_vm_drs_rule)模块不支持的参数:委托_至...“
A:清除错误消息:“ delegate_to不是vmware_vm_vm_drs_rule的参数” 。 delegate_to
的缩进是错误的。这就是为什么delegate_to
被视为模块的参数的原因。修复delegate_to
- name: Create DRS Anti Affinity Rule for VM-VM
vmware_vm_vm_drs_rule:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
cluster_name: "{{ datacenter_name }}-{{ cluster_name }}"
validate_certs: no
vms: "{{ final_list }}"
drs_rule_name: "{{ rule_name }}"
enabled: True
mandatory: True
affinity_rule: "{{ action_type }}"
delegate_to: localhost
register: rule_creation
when: final_list is defined
FWIW。使用ansible-lint验证语法。
Q:“我不想在final_list为空时执行模块。”
A:试试看
when: final_list|default([])|length > 0