Problems using ansible-inventory with community.general.lxd and remote hosts

Hi,

I’m having trouble getting ansible-inventory to work with community.general.lxd and remote hosts.

FYI, I’m using the latest version of the plugin.

git clone https://github.com/conloos/community.general.git test

I want to use ansible-inventory to list containers from a remote host. I was able to get it working with a localhost setup as a remote but not from a remote host.

Here’s my inventory file, lxd2.yml:

plugin: community.general.lxd
#url: unix:/var/snap/lxd/common/lxd/unix.socket
url: "https://192.168.1.10:8443"
type_filter: both
client_cert: "/home/cm/snap/lxd/19188/.config/lxc/client.crt"
client_key: "/home/cm/snap/lxd/19188/.config/lxc/client.key"
trust_password: "SECRET"

When I attempt to run the play it fails.

(venv) cm@cm:~/Workspace/test$ ansible-inventory -i lxd2.yml --list
[WARNING]:  * Failed to parse /home/cm/Workspace/test/lxd2.yml with auto plugin: inventory source '/home/cm/Workspace/test/lxd2.yml' could not be verified by inventory
plugin 'community.general.lxd'
[WARNING]:  * Failed to parse /home/cm/Workspace/test/lxd2.yml with yaml plugin: Plugin configuration YAML file, not YAML inventory
[WARNING]:  * Failed to parse /home/cm/Workspace/test/lxd2.yml with ini plugin: Invalid host pattern 'plugin:' supplied, ending in ':' is not allowed, this character is
reserved to provide a port.
[WARNING]: Unable to parse /home/cm/Workspace/test/lxd2.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
    "_meta": {
        "hostvars": {}
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    }
}

When trying with localhost, using trust password. lxd.yml:

plugin: community.general.lxd
#url: unix:/var/snap/lxd/common/lxd/unix.socket
url: "https://192.168.56.28:8443"
type_filter: both
client_cert: "/home/cm/snap/lxd/19188/.config/lxc/client.crt"
client_key: "/home/cm/snap/lxd/19188/.config/lxc/client.key"
trust_password: "SECRET"
(venv) cm@cm:~/Workspace/test$ ansible-inventory -i lxd.yml --list
{
    "_meta": {
        "hostvars": {
            "test": {
                "ansible_connection": "ssh",
                "ansible_host": "10.38.46.110",
                "ansible_lxd_os": "ubuntu",
                "ansible_lxd_profile": [
                    "default"
                ],
                "ansible_lxd_project": "default",
                "ansible_lxd_release": "jammy",
                "ansible_lxd_state": "running",
                "ansible_lxd_type": "container"
            }
        }
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    },
    "ungrouped": {
        "hosts": [
            "test"
        ]
    }
}

Thanks in advance!

Hi @mccaddon ,

since we have been writing back and forth on the ansible bugtracker for a while now and i assume this is a configuration issue, i suggest we look at your machine together and develop documentation together to make it easier for other users below.

I will write you a PM.

Thanks Frank

@mccaddon Did you figure this one out? I seem to be having trouble with this as well. Easy to use for the unix socket url but not for an https remote url.

Yes, @conloos helped resolve my issues. Conloos had to push a fix to the project because of self signed certificate issue, not sure if that fix made it into production yet.

Thanks, I was wondering if that was the issue. Looks like PR #6232 has not been merged yet. I’ll pull that in and try it out.