community.general
community.general copied to clipboard
Proxmox Inventory
Summary
Proxmox inventory role have been created as the example in this documentation https://docs.ansible.com/ansible/latest/collections/community/general/proxmox_inventory.html my question is how could i filter groups and hosts in order to get only the hosts that contain a specific tag (i need to work only with some hosts that contains specific tags and i want the proxmox inventory to bring only this hosts in AWX) if there any possibility to add "filters" paramter as vmware inventory
Issue Type
Bug Report
Component Name
inventory
Ansible Version
ansible --version 2.11.2
Community.general Version
`2.9
Configuration
$ ansible-config dump --only-changed
OS / Environment
No response
Steps to Reproduce
plugin: community.general.proxmox validate_certs: no want_facts: yes keyed_groups:
key: ansible_controlled separator: "" prefix: ansible
Expected Results
i expect to have only the hosts with the specific tags with ansible-inventory
Actual Results
the inventory bring all groups and hosts
Code of Conduct
- [X] I agree to follow the Ansible Code of Conduct
Files identified in the description:
If these files are incorrect, please update the component name
section of the description or use the !component
bot command.
cc @Charliekenney23 @InTheCloudDan @LBGarber @decentral1se @displague @rmcintosh click here for bot help
!component =plugins/inventory/proxmox.py
Files identified in the description:
If these files are incorrect, please update the component name
section of the description or use the !component
bot command.
cc @Ajpantuso @Thulium-Drake @ilijamt @joshainglis @karmab @tleguern click here for bot help
+1
I'm thinking of adding a flag to the options and filter out the proxmox predefined groups. please let me know if we collaborate on this. I'll be running tests locally and then when the solution is tested and fully functional I'll send a PR
Yes currently there is no filtering on the inventory. You can always run ansible with a limit on a tag after the inventory has been pulled in.
It's not just as simple as adding a filters' property. We will need to figure something out like
filters:
# All instances with their `Environment` tag set to `dev`
tag:Environment: dev
# All dev and QA hosts
tag:Environment:
- dev
- qa
we are using awx so we can't really add an argument to filter out the groups, we're trying to automate as much as possible. let me know if you know how I can start or if I can be of any help to this. cheers
I also use AWX, and we can do the filtering based on the tags in the inventory. I just make sure that my workflow/template has a limit set to the correct tag, and in Proxmox all my VM's should have the correct tag associated with them.
Here is a real example from my systems
Part of the ansible inventory:
|--@k8s:
| |--k8s-n01.example.com
| |--k8s-n02.example.com
| |--k8s-n03.example.com
| |--k8s-n04.example.com
|--@internal:
| |--k8s-n01.example.com
| |--k8s-n02.example.com
| |--k8s-n03.example.com
| |--k8s-n04.example.com
|--@php74:
| |--www.example.com
And a qm config for one of the machines
$ qm config 10041002
agent: 1,type=virtio
balloon: 0
bootdisk: scsi0
cores: 4
ide2: none,media=cdrom
memory: 8192
name: k8s-n02.example.com
net0: virtio=ff:ff:ff:ff:ff:ff,bridge=vmbr0
net1: virtio=ff:ff:ff:ff:ff:ff,bridge=vmbr4000
numa: 0
onboot: 1
ostype: l26
scsi0: storage:vm-10041002-disk-0,size=10G
scsi1: storage:vm-10041002-disk-3,size=30G
scsi2: storage:vm-10041002-disk-2,size=10G
scsihw: virtio-scsi-pci
serial0: socket
smbios1: uuid=863b31c3-42ca-4a92-aed7-4111f342f70a
sockets: 1
tablet: 0
tags: k8s,internal
vmgenid: ddfb79b2-b484-4d66-88e7-6e76f2d1be77
thank you so much for your quick feedback, truly appreciated. I'll check that out. cheers
One thing I forgot if you want to add a tag to a VM you can do so by doing from the command line
qm set 10041002 -tags "k8s,internal"
I think the vmware inventory can be used for inspiration. Their filter definition looks like this:
filters:
- runtime.powerState == "poweredOn"
- "tag_category.ansible is defined and 'managed' in tag_category.ansible"
Of course proxmox doesn't have (I think) tag categories but still composing filters like this would be awesome.
@Nouhailakermouss After reading some issue's I came up with this working configuration:
...
filters:
- proxmox_status == "running"
- "proxmox_tags_parsed is defined and 'ansible' in proxmox_tags_parsed"
...
It only return qemu_vm and lxc ressource in running state which have the tag ansible (and of course further groups to be used with ansible itself)
cc @krauthosting click here for bot help