Skip to content

MP-ES/vmm_manager_ansible_collection

Repository files navigation

Ansible collection to vmm_manager

Ansible collection to support vmm_manager application on Ansible codes.

License Integration Release

Installation and usage

Installing the collection from Ansible Galaxy

Before using the vmm_manager collection, you need to install it with the Ansible Galaxy CLI:

ansible-galaxy collection install mpes.vmm_manager

You can also include it in a requirements.yml file and install it via ansible-galaxy collection install -r requirements.yml, using the format:

---
collections:
  - name: mpes.vmm_manager

Installing the vmm_manager

This collection requires the vmm_manager application. You can install it with:

pip install vmm-manager

Using the dynamic inventory from this collection in your playbooks

Create an inventory file, named *vmm_manager.yaml, for example, test_vmm_manager.yaml with this content:

plugin: vmm_manager
vmm_inventory: test_inventory.yaml # vmm_manager inventory file
cache: True # optional
cache_plugin: jsonfile # optional

# Best practices: use environment variables to set these parameters
# vmm_access_point: 'access_server'
# vmm_server: 'scvmm_server'
# vmm_username: 'username'
# vmm_password: 'password'
# vmm_ssh_priv_key_file: '/private/key' # optional
# vmm_ssh_user: user # optional

Use the command ansible-doc -t inventory vmm_manager for more details.

Cache configuration (Optional)

If cache is enabled (recommend, due the response time of SCVMM queries), you have to set the cache plugin that Ansible will use (cache_plugin).

In case of jsonfile plugin, you have to set the cache location path, through environment variable ANSIBLE_CACHE_PLUGIN_CONNECTION, for example:

export ANSIBLE_CACHE_PLUGIN_CONNECTION=.cache

For more details about Ansible cache, see Ansible cache plugins.

Development

python-poetry configuration

# poetry installation
curl -sSL https://install.python-poetry.org | python3 -

# autocomplete configuration
# bash
poetry completions bash >> ~/.bash_completion

Dependencies

poetry install --no-root

Configurations

Set the environment variables:

export ANSIBLE_INVENTORY_PLUGINS=plugins/inventory
# if jsonfile cache is enabled
export ANSIBLE_CACHE_PLUGIN_CONNECTION=.cache

Helpful developer commands

# developer shell
poetry shell

# delete poetry virtualenv
poetry env remove python

# Load envs
export $(cat .env | xargs)

# List inventories
ansible-doc -t inventory -l

# Check documentation
ansible-doc -t inventory vmm_manager

# Test inventory list
ansible-inventory -i test_vmm_manager.yaml --list

# Run linting
flake8 . && isort --check-only --diff .

# Fix dependencies sorting
isort .

References