在 vsphere 中执行获取 vm 信息的 ansible 问题
ansible problem execut for get vm info in vsphere
我尝试执行这个 ansible yml 文件来获取 vsphere 中的虚拟机信息,
我有两个文件:
主机文件:
[Web]
192.168.11.11 #ip of my vsphere server
测试.vmware2.yaml 文件:
- name: Gather all registered virtual machines
community.vmware.vmware_vm_info:
hostname: '{{ vcenter_hostname }}'
username: '{{ vcenter_username }}'
password: '{{ vcenter_password }}'
delegate_to: localhost
register: vminfo
我用这个命令执行:
ansible -i /mnt/hosts test.vmware2.yaml
我有这条消息:
ERROR! 'community.vmware.vmware_vm_info' is not a valid attribute for a Play
The error appears to be in '/mnt/test.vmware2.yaml': line 1, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Gather all registered virtual machines
^ here
我想知道是什么问题?
感谢您的回复
我想你想执行一个 ansible-playbook:
ansible-playbook -i /mnt/hosts test.vmware2.yaml
那么您的 playbook 文件应该如下所示:
- hosts: Web
gather_facts: false
become: false
vars:
vcenter_hostname: 10.10.10.1
vcenter_username: user
vcenter_password: password
tasks:
- name: Gather all registered virtual machines
community.vmware.vmware_vm_info:
hostname: '{{ vcenter_hostname }}'
username: '{{ vcenter_username }}'
password: '{{ vcenter_password }}'
delegate_to: localhost
register: vminfo
- debug:
msg: "{{ item.guest_name }}, {{ item.ip_address }}"
with_items:
- "{{ vminfo.virtual_machines }}"
我尝试执行这个 ansible yml 文件来获取 vsphere 中的虚拟机信息,
我有两个文件:
主机文件:
[Web]
192.168.11.11 #ip of my vsphere server
测试.vmware2.yaml 文件:
- name: Gather all registered virtual machines
community.vmware.vmware_vm_info:
hostname: '{{ vcenter_hostname }}'
username: '{{ vcenter_username }}'
password: '{{ vcenter_password }}'
delegate_to: localhost
register: vminfo
我用这个命令执行:
ansible -i /mnt/hosts test.vmware2.yaml
我有这条消息:
ERROR! 'community.vmware.vmware_vm_info' is not a valid attribute for a Play
The error appears to be in '/mnt/test.vmware2.yaml': line 1, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Gather all registered virtual machines
^ here
我想知道是什么问题?
感谢您的回复
我想你想执行一个 ansible-playbook:
ansible-playbook -i /mnt/hosts test.vmware2.yaml
那么您的 playbook 文件应该如下所示:
- hosts: Web
gather_facts: false
become: false
vars:
vcenter_hostname: 10.10.10.1
vcenter_username: user
vcenter_password: password
tasks:
- name: Gather all registered virtual machines
community.vmware.vmware_vm_info:
hostname: '{{ vcenter_hostname }}'
username: '{{ vcenter_username }}'
password: '{{ vcenter_password }}'
delegate_to: localhost
register: vminfo
- debug:
msg: "{{ item.guest_name }}, {{ item.ip_address }}"
with_items:
- "{{ vminfo.virtual_machines }}"