Ansible: automatic inventory of Incus containers?

We have a varying number of Incus containers on around 4 hosts, and have taken Ansible into use in order to keep them up to date. Since we keep starting and stopping our containers rather dynamically we would like to generate an Ansible inventory automatically.
Whereas the best practice here would probably be to deploy the containers from an Ansible inventory, rather than creating the inventory after deploying the containers, I found that there is an inventory plugin community.general.lxd that does what I am after. But I could not find an Incus port so wondered if that is being planned?
If not it would probably be easy to modify the lxd plugin.

1 Like

I’ve been looking at implementing a new Incus inventory plugin for Ansible, different approach from the LXD one and more in line with our connection plugin.

This is currently on a list of potential work to be funded from some grants to the Incus project so waiting to know if that will get picked up, I believe I’ll know one way or the other by the end of September.

It’s not a lot of work and I intend to do it either way, but it’s always nice if I can have it covered by a grant :wink:

1 Like

There is an inventory plugin in this collection GitHub - kmpm/ansible-collection-incus: Collection of Ansible plugins for dealing with Incus from Linuxcontainers

Thanks for the suggestion, I am looking at it and it seems to be what I need!
However I have encountered a few issues:

  1. Incus remote is hardcoded to ‘local’ like this - I would prefer to be able to specify our remote(s)
def _populate(self):
        if len(self.data) == 0:
            cli = IncusClient(remote='local', project=self.project, debug=True)
            self.data = cli.list()
  1. Even after changing the hardcoded remote I struggle to use the plugin. What am I missing?

incus.yml looks like this

plugin: kmpm.incus.incus
type_filter: all
state_filter: running
$ ansible-inventory -i incus.yml --graph

[WARNING]:  * Failed to parse  .ansible/incus.yml with auto plugin: IncusClient.list() missing 1 required positional argument: 'filter'
[WARNING]:  * Failed to parse .ansible/incus.yml with yaml plugin: Plugin configuration YAML file, not YAML inventory
[WARNING]: Unable to parse .ansible/incus.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available

It seems a bug introduced with this commit fix: syntax for python 2.7 · kmpm/ansible-collection-incus@8a67494 · GitHub before it had a default value and I think it was mistakenly removed while removing type hints