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

Add a generic libvirt inventory plugin #10686

Open
wants to merge 3 commits into
base: devel
from

Conversation

Projects
None yet
@detiber

detiber commented Apr 13, 2015

SUMMARY

Adds an inventory plugin for libvirt (libvirt_generic).

Current limitations:

  • can only query a single provider at a time
  • only queries running guests
  • only queries the first interface returned for setting ansible_ssh_host
  • grouping by tags requires that the domain xml doc is hardcoded to use https://github.com/ansible/ansible for the xmlns namespace as follows:
<domain type='kvm' id='8'>
  <name>my-host</name>
  <memory unit='GiB'>1</memory>
  <metadata xmlns:ansible="https://github.com/ansible/ansible">
    <ansible:tag>deployment-type-{{ deployment_type }}</ansible:tag>
    <ansible:tag>env-{{ cluster }}</ansible:tag>
    <ansible:tag>env-host-type-{{ cluster }}-{{ type }}</ansible:tag>
    <ansible:tag>host-type-{{ type }}</ansible:tag>
  </metadata>
...snip...
</domain>
ISSUE TYPE

Feature Pull Request

COMPONENT NAME

plugins/inventory/libvirt.ini
plugins/inventory/libvirt_generic.py

ANSIBLE VERSION

2.3

ADDITIONAL INFORMATION

@detiber detiber force-pushed the detiber:libvirt_inventory_devel branch from aa5088c to 878fed5 Apr 16, 2015

lhuard1A and others added some commits May 23, 2015

libvirt_generic.py: Use net-dhcp-leases to find VMs’ IPs
Query libvirt’s DHCP leases rather than inspecting the host’s ARP cache
to find the VMs’ IPs.
Merge pull request #1 from lhuard1A/libvirt_inventory_devel
libvirt_generic.py: Use net-dhcp-leases to find VMs’ IPs
@amenonsen

This comment has been minimized.

Contributor

amenonsen commented Jul 28, 2015

I would be interested to use this to manage kvm/libvirt VMs. I notice that devel has a very rudimentary contrib/inventory/libvirt_lxc.py that just uses virsh list. I only skimmed this PR, but it looks much more complete. It does need a bit of revision, though (e.g. it uses argparse but should probably use optparse instead).

@detiber any interest in getting this updated and maybe merging with the existing plugin? Some explanations about how to use it would also be helpful.

@amenonsen

This comment has been minimized.

Contributor

amenonsen commented Jul 29, 2015

Sorry, please ignore what I said about argparse vs. optparse above, it was based on a misunderstanding. For the record: argparse is newer, but doesn't work with older Python (which is a problem only for modules, so using it in inventory plugins should be fine).

@detiber

This comment has been minimized.

detiber commented Aug 18, 2015

@amenonsen If anyone feels strongly on preferring optparse vs argparse I can look at swapping it out.

As far as merging with the libvirt_lxc plugin, I'm not sure what you mean as far as documenting specifically how libvirt_generic could be used in place of libvirt_lxc?

@bcoca

This comment has been minimized.

Member

bcoca commented Aug 18, 2015

ignore the parsing issues, you are good in that respect.

I missed the part about the merging ... not sure what/where that came up.

@detiber

This comment has been minimized.

detiber commented Aug 19, 2015

@bcoca It was from @amenonsen's comment

@detiber any interest in getting this updated and maybe merging with the existing plugin?

I do agree with the need for some documentation, I just wasn't sure of the best place to add it. It looks like the existing inventory scripts are hit or miss on whether they provide documentation within the comments of the script themselves, or have documentation provided via docs.ansible.com.

If you point me in the correct direction for the preferred way to document the usage of a dynamic inventory plugin, I'd be happy to write something up.

@bcoca

This comment has been minimized.

Member

bcoca commented Aug 19, 2015

currently most docs are either in the script or the config file it uses, some of them are better documented in the 'cloud' guides as they are part of the setup. For now just do where you think it fits best, later we will need to come back and make this more visible, probably pushing it to docs.ansible.com

@mattclay

This comment has been minimized.

Member

mattclay commented Dec 21, 2016

Closing and re-opening to trigger CI.

@mattclay mattclay closed this Dec 21, 2016

@mattclay mattclay reopened this Dec 21, 2016

@mattclay

This comment has been minimized.

Member

mattclay commented Dec 21, 2016

@detiber Rebase needed to get tests to pass on Shippable.

@ansibot

This comment has been minimized.

Contributor

ansibot commented Jan 6, 2017

@detiber This PR was tested by travis-ci.org, which is no longer used. Please rebase your branch to trigger running of current tests.

click here for bot help

@ansibot ansibot added the needs_rebase label Jan 8, 2017

@ansibot

This comment has been minimized.

Contributor

ansibot commented Feb 7, 2017

@detiber this PR contains the following merge comits:

Please rebase your branch to remove these commits.

click here for bot help

@ansibot

This comment has been minimized.

Contributor

ansibot commented Apr 4, 2017

@detiber Greetings! Thanks for taking the time to open this pullrequest. In order for the community to handle your pullrequest effectively, we need a bit more information.

Here are the items we could not find in your description:

  • issue type
  • ansible version
  • component name

Please set the description of this pullrequest with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/PULL_REQUEST_TEMPLATE.md

click here for bot help

@jctanner

This comment has been minimized.

Member

jctanner commented Jul 17, 2017

@detiber any chance you still have interest in this? We believe it would be a worthwhile addition and also something we should be able to test within shippable.

@pcahyna

This comment has been minimized.

Contributor

pcahyna commented Nov 24, 2017

This plugin does not work for me anymore, apparently because it outputs only the "_meta" key with host variables, no group/host list. I added output of hosts in pcahyna@bc2a2cb (all running VMs appear under a "libvirt" group).
(Otherwise it is a very useful plugin, thanks.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment