I try to execute this ansible yml file to get vm info in vsphere,
I have two files:
hosts file:
[Web]
192.168.11.11 #ip of my vsphere server
test.vmware2.yaml file:
- 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
I execute with this command:
ansible -i /mnt/hosts test.vmware2.yaml
I have this message:
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
I want to know what is the problem ?
thanks for your response
I think you want to execute an ansible-playbook:
ansible-playbook -i /mnt/hosts test.vmware2.yaml
then you playbook file should look like this:
- 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 }}"