Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promox inventory plugin #56336

Open
wants to merge 1 commit into
base: devel
from

Conversation

Projects
None yet
2 participants
@Thulium-Drake
Copy link

commented May 12, 2019

SUMMARY

I have (heavily) modified the existing foreman inventory plugin to make it work with Proxmox VE.

It collects all Proxmox Nodes, LXC containers and KVM hosts and groups them up as follows:

  • nodes
  • all lxc/qemu
  • lxc/qemu per node
  • VM's (lxc/qemu mixed) per resource pool

As an option (want_facts) it will gather the VM's configuration and wrap it in facts.

For connectivity purposes to the Proxmox nodes, it will always gather the first interface with an IP and set the ansible_host fact for that node to it.

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

proxmox

ADDITIONAL INFORMATION

As this is my first shot at helping to improve Ansible, I really look forward to your feedback (and try to make this a success! ;-))

EXAMPLE OUTPUT

Sample output from my laptop, which has 2 pools (one without hosts) and a bunch of lab VMs

$ ansible-inventory --list
/usr/local/lib/python2.7/dist-packages/urllib3/connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
{
    "_meta": {
        "hostvars": {
            "ansible-dev.lab": {
                "proxmox_arch": "amd64", 
                "proxmox_cores": 2, 
                "proxmox_digest": "d745dd32e03d92cbbffa0b6d58ee9c55b1fc1c9a", 
                "proxmox_features": {
                    "keyctl": "1", 
                    "nesting": "1"
                }, 
                "proxmox_hostname": "ansible-dev.lab", 
                "proxmox_lxc": [
                    [
                        "lxc.cgroup.devices.allow", 
                        "a"
                    ], 
                    [
                        "lxc.cap.drop", 
                        ""
                    ]
                ], 
                "proxmox_memory": 4096, 
                "proxmox_nameserver": "192.168.255.1", 
                "proxmox_net0": {
                    "bridge": "vmbr0", 
                    "firewall": "1", 
                    "gw": "192.168.255.1", 
                    "hwaddr": "9E:EB:E7:05:9B:0F", 
                    "ip": "192.168.255.20/24", 
                    "name": "eth0", 
                    "type": "veth"
                }, 
                "proxmox_ostype": "debian", 
                "proxmox_rootfs": {
                    "disk_image": "main:subvol-100-disk-0", 
                    "size": "20G"
                }, 
                "proxmox_swap": 4096
            }, 
            "apk.lab": {
                "proxmox_arch": "amd64", 
                "proxmox_cores": 1, 
                "proxmox_digest": "6286b2031d5cd2eff5cd0b454eeec3968a9334df", 
                "proxmox_hostname": "apk.lab", 
                "proxmox_memory": 2048, 
                "proxmox_nameserver": "192.168.255.1", 
                "proxmox_net0": {
                    "bridge": "vmbr0", 
                    "firewall": "1", 
                    "gw": "192.168.255.1", 
                    "hwaddr": "3A:52:D7:A0:81:93", 
                    "ip": "192.168.255.14/24", 
                    "name": "eth0", 
                    "type": "veth"
                }, 
                "proxmox_ostype": "debian", 
                "proxmox_rootfs": {
                    "disk_image": "main:subvol-106-disk-0", 
                    "size": "8G"
                }, 
                "proxmox_swap": 2048, 
                "proxmox_unprivileged": 1
            }, 
            "carrier": {
                "ansible_host": "192.168.255.1"
            }, 
            "dc.dom1.lab": {
                "proxmox_bootdisk": "virtio0", 
                "proxmox_cores": 1, 
                "proxmox_digest": "1f1eaee757d4d3e9e6b28b91bd68a50b04787c8e", 
                "proxmox_ide0": {
                    "disk_image": "data:iso/virtio-win-0.1-100.iso", 
                    "media": "cdrom", 
                    "size": "68314K"
                }, 
                "proxmox_ide2": {
                    "disk_image": "data:iso/Windows_Server_2016.ISO", 
                    "media": "cdrom"
                }, 
                "proxmox_memory": 2048, 
                "proxmox_name": "dc.dom1.lab", 
                "proxmox_net0": {
                    "bridge": "vmbr0", 
                    "virtio": "4E:0E:32:CC:00:98"
                }, 
                "proxmox_numa": 0, 
                "proxmox_ostype": "win10", 
                "proxmox_scsihw": "disk_image=virtio-scsi-pci", 
                "proxmox_smbios1": "uuid=9401a366-146b-49e2-a1de-f34294aa15ae", 
                "proxmox_sockets": 1, 
                "proxmox_virtio0": {
                    "disk_image": "main:vm-104-disk-0", 
                    "size": "32G"
                }, 
                "proxmox_vmgenid": "9f56a6ec-d77c-4225-be61-4615f16f048b"
            }, 
            "deploy.lab": {
                "proxmox_arch": "amd64", 
                "proxmox_cpulimit": "1", 
                "proxmox_cpuunits": 1024, 
                "proxmox_digest": "7395236b0de4d7447bf4b6c1f6ebe7779d81742c", 
                "proxmox_hostname": "deploy.lab", 
                "proxmox_lxc": [
                    [
                        "lxc.apparmor.profile", 
                        "unconfined"
                    ], 
                    [
                        "lxc.mount.entry", 
                        "/data/local/sambashare sambashare none bind 0 0"
                    ]
                ], 
                "proxmox_memory": 768, 
                "proxmox_nameserver": "192.168.255.1", 
                "proxmox_net0": {
                    "bridge": "vmbr0", 
                    "gw": "192.168.255.1", 
                    "hwaddr": "1A:23:CA:61:15:8C", 
                    "ip": "192.168.255.10/24", 
                    "name": "eth0", 
                    "type": "veth"
                }, 
                "proxmox_onboot": 0, 
                "proxmox_ostype": "debian", 
                "proxmox_rootfs": {
                    "disk_image": "main:subvol-102-disk-1", 
                    "size": "45G"
                }, 
                "proxmox_searchdomain": "element-networks.nl", 
                "proxmox_swap": 768
            }, 
            "esxi.dom1.lab": {
                "proxmox_bootdisk": "sata0", 
                "proxmox_cores": 2, 
                "proxmox_cpu": "host", 
                "proxmox_digest": "197bcc16b33d4011562887368747bdcb279cee03", 
                "proxmox_ide2": {
                    "disk_image": "data:iso/VMware-VMvisor-Installer-201701001-4887370.x86_64.iso", 
                    "media": "cdrom"
                }, 
                "proxmox_memory": 6144, 
                "proxmox_name": "esxi.dom1.lab", 
                "proxmox_net0": {
                    "bridge": "vmbr0", 
                    "e1000": "36:B9:94:C0:1B:ED"
                }, 
                "proxmox_numa": 0, 
                "proxmox_ostype": "l26", 
                "proxmox_sata0": {
                    "disk_image": "main:vm-108-disk-0", 
                    "size": "60G"
                }, 
                "proxmox_scsihw": "disk_image=virtio-scsi-pci", 
                "proxmox_smbios1": "uuid=0d66874d-fbd5-4abe-9870-039dcc5a0f5f", 
                "proxmox_sockets": 1, 
                "proxmox_vmgenid": "cfd4f5ad-1ca3-4979-be94-88bff2739e06"
            }, 
            "kali.lab": {
                "proxmox_bootdisk": "virtio0", 
                "proxmox_cores": 2, 
                "proxmox_digest": "d74088345c54ee81d0d50e246a749851879e54f1", 
                "proxmox_ide2": {
                    "disk_image": "data:iso/kali-linux-xfce-2019.1a-amd64.iso", 
                    "media": "cdrom", 
                    "size": "3199724K"
                }, 
                "proxmox_memory": 4096, 
                "proxmox_name": "kali.lab", 
                "proxmox_net0": {
                    "bridge": "vmbr0", 
                    "firewall": "1", 
                    "virtio": "66:9A:E2:63:7E:6B"
                }, 
                "proxmox_numa": 0, 
                "proxmox_ostype": "l26", 
                "proxmox_scsihw": "disk_image=virtio-scsi-pci", 
                "proxmox_smbios1": "uuid=968c2848-8a9f-4a07-9ea7-b15430a99ecb", 
                "proxmox_sockets": 1, 
                "proxmox_usb0": "host=2-1", 
                "proxmox_virtio0": {
                    "disk_image": "main:vm-109-disk-0", 
                    "size": "32G"
                }, 
                "proxmox_vmgenid": "8c12b024-bb17-47e3-af6f-cdaebc7a5cb5"
            }, 
            "labns.lab": {
                "proxmox_arch": "amd64", 
                "proxmox_cores": 1, 
                "proxmox_digest": "de518c807f42bb957c85d9a7129754bcc3220be3", 
                "proxmox_hostname": "labns.lab", 
                "proxmox_memory": 512, 
                "proxmox_nameserver": "192.168.255.1", 
                "proxmox_net0": {
                    "bridge": "vmbr0", 
                    "gw": "192.168.255.1", 
                    "hwaddr": "8E:E9:65:8A:5F:B7", 
                    "ip": "192.168.255.150/24", 
                    "name": "eth0", 
                    "type": "veth"
                }, 
                "proxmox_onboot": 1, 
                "proxmox_ostype": "debian", 
                "proxmox_rootfs": {
                    "disk_image": "main:subvol-103-disk-0", 
                    "size": "8G"
                }, 
                "proxmox_swap": 512, 
                "proxmox_unprivileged": 1
            }, 
            "pydev.lab": {
                "proxmox_arch": "amd64", 
                "proxmox_cores": 1, 
                "proxmox_digest": "dbb9e129eb779220a37713ab3f5bbd3dd66ca810", 
                "proxmox_hostname": "pydev.lab", 
                "proxmox_memory": 512, 
                "proxmox_nameserver": "192.168.255.1", 
                "proxmox_net0": {
                    "bridge": "vmbr0", 
                    "gw": "192.168.255.1", 
                    "hwaddr": "E6:DC:DE:54:96:17", 
                    "ip": "192.168.255.105/24", 
                    "name": "eth0", 
                    "type": "veth"
                }, 
                "proxmox_ostype": "debian", 
                "proxmox_rootfs": {
                    "disk_image": "main:subvol-105-disk-0", 
                    "size": "8G"
                }, 
                "proxmox_swap": 512
            }, 
            "rhel.dom1.lab": {
                "proxmox_bootdisk": "virtio0", 
                "proxmox_cores": 2, 
                "proxmox_digest": "93556704d1996925bfc5def3feb7b037871e3ece", 
                "proxmox_ide2": {
                    "disk_image": "data:iso/rhel-server-7.6-x86_64-dvd.iso", 
                    "media": "cdrom"
                }, 
                "proxmox_memory": 4096, 
                "proxmox_name": "rhel.dom1.lab", 
                "proxmox_net0": {
                    "bridge": "vmbr0", 
                    "virtio": "9A:E5:C1:22:A4:59"
                }, 
                "proxmox_numa": 0, 
                "proxmox_ostype": "l26", 
                "proxmox_scsihw": "disk_image=virtio-scsi-pci", 
                "proxmox_smbios1": "uuid=648fe832-6182-4904-b7cd-f6fbbde3bdae", 
                "proxmox_sockets": 1, 
                "proxmox_virtio0": {
                    "disk_image": "main:vm-107-disk-0", 
                    "size": "32G"
                }, 
                "proxmox_vmgenid": "d17fc727-13fa-4d4e-ad4f-f59f36a57cf9"
            }, 
            "win.lab": {
                "proxmox_bootdisk": "virtio0", 
                "proxmox_cores": 1, 
                "proxmox_digest": "4592bf7efee03c22286e523e906d35c9076ba7b6", 
                "proxmox_ide2": {
                    "disk_image": "data:iso/virtio-win-0.1-100.iso", 
                    "media": "cdrom", 
                    "size": "68314K"
                }, 
                "proxmox_memory": 4096, 
                "proxmox_name": "win.lab", 
                "proxmox_net0": {
                    "bridge": "vmbr0", 
                    "virtio": "2A:9A:26:80:02:1F"
                }, 
                "proxmox_numa": 0, 
                "proxmox_ostype": "win7", 
                "proxmox_scsihw": "disk_image=virtio-scsi-pci", 
                "proxmox_smbios1": "uuid=afba98c8-8fb2-4788-90c1-81ce5acaadc3", 
                "proxmox_sockets": 1, 
                "proxmox_usb0": "host=1-4", 
                "proxmox_virtio0": {
                    "disk_image": "main:vm-101-disk-1", 
                    "size": "32G"
                }
            }
        }
    }, 
    "all": {
        "children": [
            "proxmox_all_lxc", 
            "proxmox_all_qemu", 
            "proxmox_carrier_lxc", 
            "proxmox_carrier_qemu", 
            "proxmox_nodes", 
            "proxmox_pool_dom1_lab", 
            "proxmox_pool_test", 
            "ungrouped"
        ]
    }, 
    "proxmox_all_lxc": {
        "hosts": [
            "ansible-dev.lab", 
            "apk.lab", 
            "deploy.lab", 
            "labns.lab", 
            "pydev.lab"
        ]
    }, 
    "proxmox_all_qemu": {
        "hosts": [
            "dc.dom1.lab", 
            "esxi.dom1.lab", 
            "kali.lab", 
            "rhel.dom1.lab", 
            "win.lab"
        ]
    }, 
    "proxmox_carrier_lxc": {
        "hosts": [
            "ansible-dev.lab", 
            "apk.lab", 
            "deploy.lab", 
            "labns.lab", 
            "pydev.lab"
        ]
    }, 
    "proxmox_carrier_qemu": {
        "hosts": [
            "dc.dom1.lab", 
            "esxi.dom1.lab", 
            "kali.lab", 
            "rhel.dom1.lab", 
            "win.lab"
        ]
    }, 
    "proxmox_nodes": {
        "hosts": [
            "carrier"
        ]
    }, 
    "proxmox_pool_dom1_lab": {
        "hosts": [
            "dc.dom1.lab", 
            "esxi.dom1.lab", 
            "rhel.dom1.lab"
        ]
    }, 
    "proxmox_pool_test": {}, 
    "ungrouped": {}
}

@Thulium-Drake

This comment has been minimized.

Copy link
Author

commented May 12, 2019

I've checked the output from Shippable, but I think that test is wrong. There's 1 test that failed and it mentions the following error:

ERROR: lib/ansible/plugins/inventory/proxmox.py:62:0: ansible-bad-import-from Import MutableMapping from ansible.module_utils.common._collections_compat instead of collections (100%)

However, line 62 of the plugin script reads as follows:

from collections import MutableMapping

Did I do something wrong? (If so, this error is also in the Foreman plugin)

@ansibot

This comment has been minimized.

Copy link
Contributor

commented May 20, 2019

@Thulium-Drake this PR contains the following merge commits:

Please rebase your branch to remove these commits.

click here for bot help

@Thulium-Drake Thulium-Drake force-pushed the Thulium-Drake:devel branch from 881d7be to 11fc5ad May 20, 2019

@Thulium-Drake

This comment has been minimized.

Copy link
Author

commented May 20, 2019

Rebased as suggested by the bot

@Thulium-Drake

This comment has been minimized.

Copy link
Author

commented May 20, 2019

bot_status

@ansibot

This comment has been minimized.

Copy link
Contributor

commented May 20, 2019

Components

lib/ansible/plugins/inventory/proxmox.py
support: community
maintainers:

Metadata

waiting_on: Thulium-Drake
changes_requested_by: null
needs_info: False
needs_revision: True
needs_rebase: False
merge_commits: []
too many files or commits: False
mergeable_state: unstable
shippable_status: failure
maintainer_shipits (module maintainers): False
community_shipits (namespace maintainers): False
ansible_shipits (core team members): False
shipit_actors (maintainer or core team member): None
shipit_actors_other:
automerge: automerge shipit test failed

click here for bot help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.