Inventory
This directory contains both static and dynamic inventory configurations.
Inventory Files
Section titled “Inventory Files”Static Inventory
Section titled “Static Inventory”hosts.ini- Static inventory for localhost testing
Dynamic Inventory
Section titled “Dynamic Inventory”proxmox.proxmox.yml- Proxmox VE dynamic inventory plugin configuration
Setting Up Proxmox Dynamic Inventory
Section titled “Setting Up Proxmox Dynamic Inventory”Prerequisites
Section titled “Prerequisites”- Install Required Collection
# Install community.proxmox collectionansible-galaxy collection install community.proxmox
# Or install from requirementsansible-galaxy collection install -r ../collections/requirements.yml- Create API Token in Proxmox
In your Proxmox web interface:
- Navigate to Datacenter → Permissions → API Tokens
- Click Add
- Configure:
- User:
root@pam(or your preferred user) - Token ID:
ansible - Privilege Separation: Uncheck (or configure appropriate permissions)
- User:
- Copy the secret - it will only be shown once!
Configuration
Section titled “Configuration”For Local Testing (Using .env File)
Section titled “For Local Testing (Using .env File)”# Copy the example filecp ../.env.example ../.env
# Edit and add your Proxmox token secretnano ../.envAdd:
PROXMOX_TOKEN_SECRET=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxFor Semaphore UI (Using Variable Groups - Recommended)
Section titled “For Semaphore UI (Using Variable Groups - Recommended)”Semaphore UI has built-in secret management that’s more secure:
- In Semaphore, go to your project
- Navigate to Variable Groups
- Click “New Variable Group”
- Name it (e.g., “Proxmox Credentials”)
- Add JSON with your secrets:
{ "PROXMOX_TOKEN_SECRET": "your-actual-token-secret-here", "PROXMOX_URL": "https://proxmox.example.com:8006"}Benefits:
- Secrets are automatically masked in logs
- Centralized secret management
- No need for
.envfiles in the repository - Variables passed securely at runtime
- Associate the Variable Group with your Task Template
Update Proxmox URL
Section titled “Update Proxmox URL”Edit proxmox.proxmox.yml and update the url field:
url: http://your-proxmox-host:8006Or use HTTPS with your domain:
url: https://proxmox.yourdomain.com:8006validate_certs: true # Set to true if using valid SSL certTesting the Inventory
Section titled “Testing the Inventory”List All Hosts
Section titled “List All Hosts”# From ansible directorycd /home/unknown224/ubuntu-server-config/ansible
# List all discovered hostsansible-inventory -i inventory/proxmox.proxmox.yml --list
# List hosts in graph formatansible-inventory -i inventory/proxmox.proxmox.yml --graph
# List specific groupansible-inventory -i inventory/proxmox.proxmox.yml --graph virtual_machinesTest Connectivity
Section titled “Test Connectivity”# Ping all Proxmox hostsansible all -i inventory/proxmox.proxmox.yml -m ping
# Ping specific groupansible virtual_machines -i inventory/proxmox.proxmox.yml -m ping
# Ping hosts with specific tagansible tag_web -i inventory/proxmox.proxmox.yml -m pingGet Host Details
Section titled “Get Host Details”# Get details for a specific hostansible-inventory -i inventory/proxmox.proxmox.yml --host <hostname>
# List all groupsansible-inventory -i inventory/proxmox.proxmox.yml --list | jq 'keys'Proxmox Host Grouping
Section titled “Proxmox Host Grouping”The dynamic inventory automatically creates groups based on:
1. Tags (Recommended)
Section titled “1. Tags (Recommended)”Tag your VMs/containers in Proxmox (Format: web;production;debian):
tag_web- Hosts tagged with “web”tag_production- Hosts tagged with “production”tag_debian- Hosts tagged with “debian”
2. Type
Section titled “2. Type”virtual_machines- All QEMU VMscontainers- All LXC containerstype_qemu- QEMU VMstype_lxc- LXC containers
3. Status
Section titled “3. Status”status_running- All running hostsstatus_stopped- All stopped hosts
4. Node
Section titled “4. Node”node_pve1- Hosts on node “pve1”node_pve2- Hosts on node “pve2”
5. Custom Groups
Section titled “5. Custom Groups”Pre-configured in proxmox.proxmox.yml:
debian- Hosts tagged with “debian”ubuntu- Hosts tagged with “ubuntu”production- Hosts tagged with “production”staging- Hosts tagged with “staging”development- Hosts tagged with “development”
Using with Playbooks
Section titled “Using with Playbooks”Single Inventory
Section titled “Single Inventory”ansible-playbook -i inventory/proxmox.proxmox.yml playbooks/your-playbook.ymlMultiple Inventories
Section titled “Multiple Inventories”# Use both static and dynamic inventoryansible-playbook -i inventory/hosts.ini -i inventory/proxmox.proxmox.yml playbooks/your-playbook.ymlTarget Specific Groups
Section titled “Target Specific Groups”---# playbook example- name: Configure web servers hosts: tag_web tasks: - name: Install nginx apt: name: nginx state: presentUsing with Semaphore UI
Section titled “Using with Semaphore UI”Step-by-Step Setup
Section titled “Step-by-Step Setup”1. Create Variable Group (for secrets)
- Go to Variable Groups in your project
- Click “New Variable Group”
- Name:
Proxmox Credentials - JSON content:
{ "PROXMOX_TOKEN_SECRET": "your-actual-token-secret", "PROXMOX_URL": "https://proxmox.example.com:8006"}- Secrets will be automatically masked in logs
2. Create Inventory
- Go to Inventories
- Click “New Inventory”
- Name:
Proxmox Dynamic - Type: File
- Inventory Path:
ansible/inventory/proxmox.proxmox.yml
3. Create Task Template
- Go to Task Templates
- Click “New Template”
- Configure:
- Name:
Deploy to Proxmox VMs - Playbook Filename:
ansible/playbooks/your-playbook.yml - Inventory: Select
Proxmox Dynamic - Environment (Variable Group): Select
Proxmox Credentials
- Name:
4. Run the Task
- The inventory will automatically discover all running VMs/containers
- Secrets are passed securely at runtime
- Logs will show masked values for sensitive data
Alternative: Using Key Store
Section titled “Alternative: Using Key Store”For even more secure credential storage:
- Go to Key Store
- Add a Login with Password type key
- Name:
Proxmox API Token - Username:
root@pam!ansible(full token identifier) - Password: Your token secret
Then reference this key in your inventory configuration or as an Ansible vault password.
Troubleshooting
Section titled “Troubleshooting”“Plugin not found” Error
Section titled ““Plugin not found” Error”Install the collection:
ansible-galaxy collection install community.proxmoxAuthentication Errors
Section titled “Authentication Errors”- Local testing: Verify token secret in
.envfile - Semaphore: Check Variable Group has correct
PROXMOX_TOKEN_SECRET - Verify token permissions in Proxmox (ensure token has proper privileges)
- Ensure user has appropriate privileges for VM/container access
- Test with curl to verify API access (see command below)
No Hosts Found
Section titled “No Hosts Found”- Verify Proxmox URL is correct
- Check that VMs/containers are running (filter:
status == "running") - Test API access:
curl -k "https://proxmox.example.com:8006/api2/json/cluster/resources" \ -H "Authorization: PVEAPIToken=root@pam!ansible=your-token-secret"SSL Certificate Errors
Section titled “SSL Certificate Errors”If using self-signed certificates, set in proxmox.proxmox.yml:
validate_certs: falseCache Issues
Section titled “Cache Issues”Clear the inventory cache:
rm -rf /tmp/ansible_proxmox_cacheBest Practices
Section titled “Best Practices”- Use Tags - Organize your Proxmox VMs/containers with meaningful tags
- API Tokens - Prefer API tokens over password authentication
- Semaphore Variable Groups - Use Semaphore’s built-in secret management for production
- Local .env Files - Use
.envfiles only for local testing (never commit to git) - Limit Scope - Use filters to only include necessary hosts
- Test First - Always test inventory with
ansible-inventory --listbefore running playbooks - Cache Wisely - Use caching for better performance, but clear when changes are made
- Document Tags - Maintain a list of tag conventions for your infrastructure
Example Workflow
Section titled “Example Workflow”# 1. Tag VMs in Proxmox: "web;production;ubuntu"
# 2. Test inventoryansible-inventory -i inventory/proxmox.proxmox.yml --graph
# 3. Verify connectivityansible tag_web -i inventory/proxmox.proxmox.yml -m ping
# 4. Run playbookansible-playbook -i inventory/proxmox.proxmox.yml playbooks/configure-web-servers.yml
# 5. Target specific environmentansible-playbook -i inventory/proxmox.proxmox.yml playbooks/deploy.yml --limit production