Using Ansible to Update ESXI VIB’s and manage vCenter at scale.

Recently I’ve been using Ansible to push out updates to vSphere environments that have a lot of hosts, but no working installation of VMWare Update Manager available. During the creation of the below playbook, I found a few interesting caveats to using Ansible to manage your ESXI hosts and vCenter. To resolve this, I’ve created a playbook that does the following:

  • Puts targeted hosts in mainteance mode and evacuates VM’s
  • Copies VIB to the host
  • Checks for existing installation of VIB, Uninstall if found
  • Installs VIB
  • Takes host out of maintenance mode.

When you manage vCenter, you use the vmware_maintenancemode Ansible module. This module requires pyvomi to function, but this is a module you have to import to your Python installation to be accessible by the Python interpreter that Ansible launches. If you don’t have it installed, you get this error:

ModuleNotFoundError: No module named 'pyVim' >>>

To import that module, all that it takes is

pip install pyvmomi

However, you may still still receive that error about the missing module. The reason you may be getting this error even after installing the module, is that your installed you installed Ansible with a package manager (Homebrew in my case). When you install ansible that way, It creates a different installation of Python3 in /usr/local/cellar – and searches for the modules in there.

To resolve this, make sure to install Ansible with

python3 -m pip install ansible

That will ensure the Ansible python module location is correct. Here’s what it should look like.

$ ansible --version
ansible 2.9.10
config file = /Users/nshores/ansible.cfg
configured module search path = ['/Users/nshores/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.8.3 (default, Jul 7 2020, 13:01:48) [Clang 11.0.0 (clang-1100.0.33.17)]

The other issue that came up with the below playbook was the usage of the copy module. To install the VIB, we need to SCP the file over to the destination host as part of the copy task. However, Initially I was faced with out of space errors when trying to do this –

fatal: [dc-esxihost-01.example.com]: FAILED! => {"msg": "failed to transfer file to /Users/nshores/downloads/NVIDIA-GRID-vSphere-6.7-450.55-450.51.05-451.48/NVIDIA-VMware-450.55-1OEM.670.0.0.8169922.x86_64.vib /.ansible/tmp/ansible-tmp-1594275906.314383-83139-22819627085371/source:\n\ndd: writing '/.ansible/tmp/ansible-tmp-1594275906.314383-83139-22819627085371/source': No space left on device\n0+1518 records in\n0+1517 records out\n"}

This is caused by the default temporary file path of ansible to be /.ansible/tmp. Only ESXI (And other systems) there may not be space to put files here. We can resolve this by setting the ansible_remote_tmp variable to /tmp in our inventory file.

To use the below playbook, you need a inventory file that looks like this.

[dunn-esxi]
dc-esxihost-01.examplehost.com
dc-esxihost-02.examplehost.com




[dunn-esxi:vars]
ansible_python_interpreter=/usr/bin/python3
ansible_connection=ssh
ansible_user=root
ansible_ssh_private_key_file=~/.ssh/id_rsa
vcenter_username = you_vcenter_username
vcenter_hostname = your_veenter_hostname
vcenter_password = your_vcenter_password
ansible_remote_tmp = /tmp

 

Share this content:

Leave a Comment

Your email address will not be published. Required fields are marked *