我是ansible的新手。我正试图从esxi获取有关安装在其上的虚拟机的信息。没有可用的vcentre。
我已经创建了剧本。连接正在工作,但是我在任务调试中收到错误。非常感谢您的帮助。感谢
行动手册:
- hosts: esxi
gather_facts: false
become: false
tasks:
- name: Gather all registered virtual machines
community.vmware.vmware_vm_info:
hostname: '{{ hostname }}'
username: '{{ ansible_user }}'
password: '{{ password }}'
validate_certs: no
delegate_to: localhost
register: vminfo
- debug:
msg: "{{ item.guest_name }}, {{ item.ip_address }}"
with_items:
- "{{ vminfo.virtual_machines }}"
错误为:
TASK [debug] *************************************************************************************************************************
fatal: [192.168.233.202]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'item' is undefinednnThe error appears to be in '/home/sciclunam/task4/playbook11.yaml': line 14, column 8, but maynbe elsewhere in the file depending on the exact syntax problem.nnThe offending line appears to be:nnn - debug:n ^ heren"}
PLAY RECAP ***************************************************************************************************************************
192.168.233.202 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
在Ansible中,正确的缩进是非常必要的。您的with_items
缩进不正确。
请注意wiith_items
的缩进
这是我的样品
# Create Directory Structure
- name: Create directory application
file:
path: "{{item}}"
state: directory
mode: 0755
with_items:
- "/opt/project1"
- "/opt/project1/script"
- "/opt/project1/application"