Skip to main content

Ansible Inventory Plugin for CMDBSyncer

Project description

CMDBSyncer Inventory Plugin

PyPI version Python Support License: MIT

An Ansible dynamic inventory plugin that fetches host and group information from CMDBSyncer.

Installation

Via pip (Recommended)

# Install the package
pip install cmdbsyncer-inventory

# Auto-install plugin for Ansible (run once after installation)
python -m cmdbsyncer_inventory

That's it! The plugin is now automatically available to Ansible.

Alternative methods

Method 1: Using the install command (if available)

cmdbsyncer-install-plugin  # If console scripts work on your system

Method 2: Manual copy to project

# Install the package
pip install cmdbsyncer-inventory

# Manually copy to your project
mkdir -p inventory_plugins
python -c "
import cmdbsyncer_inventory
from pathlib import Path
import shutil

src = Path(cmdbsyncer_inventory.__file__).parent / 'inventory_plugins' / 'cmdbsyncer_inventory.py'
shutil.copy2(src, 'inventory_plugins/cmdbsyncer_inventory.py')
print('Plugin copied to ./inventory_plugins/')
"

Via pip from source

pip install git+https://github.com/kuhn-ruess/cmdbsyncer-inventory.git
python -m cmdbsyncer_inventory

Usage

After installation and running python -m cmdbsyncer_inventory, the plugin is automatically available to Ansible. You just need to:

  1. Create an inventory configuration file (e.g., inventory.yml):
plugin: cmdbsyncer_inventory
api_url: https://your-cmdbsyncer-instance.com
username: your_username  # Optional if using environment variables
password: your_password  # Optional if using environment variables
  1. Set environment variables (recommended for credentials):
export CMDBSYNCER_APIUSER="your_username"
export CMDBSYNCER_APIPASSWORD="your_password"
  1. Use with ansible commands:
# Test the inventory
ansible-inventory -i inventory.yml --list

# Run playbooks
ansible-playbook -i inventory.yml your-playbook.yml

Note: No ansible.cfg configuration needed after automatic installation!

Configuration Options

Option Required Type Description
plugin Yes string Must be cmdbsyncer_inventory
api_url Yes string URL to your CMDBSyncer instance
username No string API username (can use CMDBSYNCER_APIUSER env var)
password No string API password (can use CMDBSYNCER_APIPASSWORD env var)

Example Output

The plugin will create Ansible inventory with hosts and groups based on your CMDBSyncer configuration. Example structure:

{
  "_meta": {
    "hostvars": {
      "server1.example.com": {
        "ansible_host": "10.0.0.1",
        "ansible_user": "admin",
        "environment": "production"
      }
    }
  },
  "production": {
    "hosts": ["server1.example.com"]
  },
  "web": {
    "hosts": ["server1.example.com"]  
  }
}

Requirements

  • Python 3.7+
  • Ansible Core 2.12+
  • CMDBSyncer instance with API access

Development

Local Development Setup

# Clone the repository
git clone https://github.com/kuhn-ruess/cmdbsyncer-inventory.git
cd cmdbsyncer-inventory

# Install in development mode
pip install -e .

# Install plugin for Ansible
python -m cmdbsyncer_inventory

# Test the plugin
ansible-inventory -i example-inventory.yml --list

Building for PyPI

# Install build tools
pip install build twine

# Build package
python -m build

# Upload to PyPI
python -m twine upload dist/*

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cmdbsyncer_inventory-0.1.2.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cmdbsyncer_inventory-0.1.2-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file cmdbsyncer_inventory-0.1.2.tar.gz.

File metadata

  • Download URL: cmdbsyncer_inventory-0.1.2.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for cmdbsyncer_inventory-0.1.2.tar.gz
Algorithm Hash digest
SHA256 12e1dc8a33d3ae7672426bdeb724fe2b23e166c319b2f0fcbfa7e479ae03b302
MD5 4389e2eed439d065bb38b8979ea6c851
BLAKE2b-256 3ceed7f37b0ee5362c3598c8ad8e89f7b4a9acf9c79bf33045c26faac2bde4a2

See more details on using hashes here.

File details

Details for the file cmdbsyncer_inventory-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for cmdbsyncer_inventory-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8df7efbf186f4bf4f2d719e1df9f6bd9bde2be167137dd97a85c904a1df2cbd7
MD5 5de665038ddef100ef75ae8fd80c2169
BLAKE2b-256 8068c7cbcebc9c42480d50d3081938872e03cd8ec692ab3f6905d57802ee5546

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page