我是 ansible 的新手。我正在尝试从 esxi 获取有关其上安装的虚拟机的信息。没有可用的 vcenter。
我已经创建了剧本。连接正在工作,但是我在任务调试中收到错误。任何帮助深表感谢。谢谢
剧本:
- 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 }}"
Run Code Online (Sandbox Code Playgroud)
错误是:
TASK [debug] *************************************************************************************************************************
fatal: [192.168.233.202]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'item' is undefined\n\nThe error appears to be in '/home/sciclunam/task4/playbook11.yaml': line 14, column 8, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - debug:\n ^ here\n"}
PLAY RECAP ***************************************************************************************************************************
192.168.233.202 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Run Code Online (Sandbox Code Playgroud)
在 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"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8457 次 |
| 最近记录: |