Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

VMware ansible Error couldn't resolve module community.vmware

Recently while working with one of the old ansible server where I wanted to automation to get the list of VMware vCenter virtual machines list, and the ansible playbook was failing due to few prerequisite, In below script I was using community.vmware.vmware_vm_info ansible module/plugin to get the list of  VMs.

Another Error:  Ansible Error couldn't resolve module vmware.vmware_rest

- name: Virutal Machine - Snapshot, Shutdown, Upgrade Hardware, verify, Power on
  hosts: localhost
  gather_facts: no

  tasks:
    - name: Gather all registered virtual machines
      community.vmware.vmware_vm_info:
        hostname: '{{ secret.hostname }}'
        username: '{{ secret.username }}'
        password: '{{ secret.password }}'
        vm_type: vm
        validate_certs: no
      delegate_to: localhost
      register: vminfo

    - debug:
        var: vminfo

While running ansible playbook to list of VMs on the vCenter I was receiving below error.

vmware vsphere esxi vcenter virtual machine automation devops ansible ansible-playbook galaxy yml yaml community.vmware.vmware_vm_info update.yml root.png

[root@centos02 ansible]$  ansible-playbook update.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

ERROR! couldn't resolve module/action 'community.vmware.vmware_vm_info'. This often indicates a misspelling, missing collection, or incorrect module path.

The error appears to be in '/root/ansible/update.yml': line 48, column 7, 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

To resovled this first I checked one of the prerequisite whether pyvmomi python package is installed, which was not present.

vmware vsphere vcenter esxi automation ansible centos ubuntu playbook yaml pip show pyvmomi python pip3 package not found ansible-playbook inventory.png

pip show pyvmomi

I installed the package, with pip since I was running python 2.7 version. if you are using python 3.x version you can use pip3 instead of pip.

Redhat ansible vmware vsphere vcenter esxi automation devops pip install pyvmomi pip show pip3 install vmware vsphere python sdk github ansible-playbook ansible-galaxy yum update ansible module package.png

[root@centos02 ansible]$  pip install pyvmomi
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Requirement already satisfied: pyvmomi in /usr/lib/python2.7/site-packages (7.0.1)
Requirement already satisfied: requests>=2.3.0 in /usr/lib/python2.7/site-packages (from pyvmomi) (2.20.1)
Requirement already satisfied: six>=1.7.3 in /usr/lib/python2.7/site-packages (from pyvmomi) (1.14.0)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python2.7/site-packages (from requests>=2.3.0->pyvmomi) (2019.11.28)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/lib/python2.7/site-packages (from requests>=2.3.0->pyvmomi) (3.0.4)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/lib/python2.7/site-packages (from requests>=2.3.0->pyvmomi) (1.24.3)
Requirement already satisfied: idna<2.8,>=2.5 in /usr/lib/python2.7/site-packages (from requests>=2.3.0->pyvmomi) (2.7)
[root@centos02 ansible]$  pip show pyvmomi
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Name: pyvmomi
Version: 7.0.1
Summary: VMware vSphere Python SDK
Home-page: https://github.com/vmware/pyvmomi
Author: VMware, Inc.
Author-email: jhu@vmware.com
License: License :: OSI Approved :: Apache Software License
Location: /usr/lib/python2.7/site-packages
Requires: requests, six
Required-by: 
[root@centos02 ansible]$

Another prerequisite missing was comminity.vmware collection module which need to be installed using ansible-galaxy.

ansible-galaxy collection install community.vmware dependacy ansible_collections vmware vsphere esxi vcenter automation devops pip pip3 show install redhat ansible centos ubuntu linux playbook yml yaml.png

[root@centos02 ansible]$  ansible-galaxy collection install community.vmware
Process install dependency map
Starting collection install process
Installing 'community.vmware:1.7.0' to '/root/.ansible/collections/ansible_collections/community/vmware

After executing the ansible yml playbook again All was good and I got the 

ansible-playbook update.yml yaml playbook devops vmware vsphere vcenter esxi virtulization module plugin ansible tasks play virtual machine list ansible-galaxy collection.png

Userful Articles
Getting started Ansible AWX tower for IT automation run first playbook
Ansible for VMwary Using vmware_vm_inventory dynamic inventory plugin
Ansible selectattr The error was TemplateRuntimeError no test named 'equalto'
ansible create an array with set_fact
Ansible get information from esxi advanced settings nested dictionary with unique keynames
Install Ansible AWX Tower on Ubuntu Linux
Ansible AWX installation error Cannot have both the docker-py and docker python modules
Ansible AWX installation error docker-compose run --rm --service-ports task awx-manage migrate --no-input
docker: Got permission denied while trying to connect to the Docker daemon socket
Ansible AWX Tower create Manual SCM (Source Control Credential Type) project
Reset Ansible AWX Tower admin password

Go Back

Comment

Blog Search

Page Views

5542132

Follow me on Blogarama