/ansible-vcenter

Ansible vcenter inventory script

Primary LanguagePythonMIT LicenseMIT

vcenter ansible scripts

inventory

Dynamic inventory scripts for ansible and vcenter. This script provides example how to use pyvmomi api. Nowadays Ansible provides production-ready inventory plugin vmware_inventory.py

Based on:

dependiences

sudo dnf install python-pyvmomi PyYAML

usage

  • Copy vcenter_inv.yml.dist to vcenter_inv.yml and edit hostname, user, password. Or you can use one yaml config file with variables for ansible vsphere_guest module and vcenter_inv.py (just create symlink to group_vars/all, for example). Also, you can put configuration file to any place and set VCENTER_INV_CFG environment variable to it.
  • Run ./vcenter_inv.py --list:

Example output:

{
    "vcenter": {
        "children": [
            "centos64Guest",
            "sles11_64Guest"
        ]
    },
    "sles11_64Guest": {
        "hosts": [
            "192.168.1.13",
        ]
    },
    "centos64Guest": {
        "hosts": [
            "192.168.1.14",
            "192.168.1.15"
        ]
    }
}
  • Run ansible ping with '-i' options:
# export VCENTER_INV_CFG=~/.ansible/vcenter_inv.py
ansible -i path/to/vcenter_inv.py -m ping

or add to ansible.cfg:

[defaults]
inventory = path/to/inventory/vcenter_inv.py