Ansible dynamic inventory

Hi @all,

i have developed a dynamic inventory plugin for lxd and looking for testers. The plugin is available on github and i will start cleanup and refactoring in the coming days.

The following filters for groups are currently implemented:
- location: no idea if it works, i grabbed examples from bugreports -> need sample
- pattern: e.g. samba * or regex
- network_range: e.g. 192.168.0.0/24 or fd42: bd00: 7b11: 2167: 216: 3eff :: / 24
- os: e.g. ubuntu
- release: e.g. groovy
- profile: e.g. default
- vlanid: e.g. 666

repo: https://github.com/conloos/community.general
plugin path: plugins/inventory/lxd.py
testdata: plugins/inventory/test/lxd_inventory.atd
ansible config: plugins/inventory/test/lxd.py

For testing, the following structure must be created, i use symlinks:

inventory_plugins/lxd.py -> …/…/ansible-collections/plugins/inventory/lxd.py
inventory_plugins/test -> …/…/ansible-collections/plugins/inventory/test/
lxd.yml -> …/ansible-collections/plugins/inventory/test/lxd.yml

The test is started by the following command:
$ ansible-inventory -i lxd.yml --playbook-dir ./ --list

In the ansible config: “plugins/inventory/test/lxd.py” is by default “selftest: True”, to start a realworld test, please set it to False and adjust the config according to your needs.

Should it fail, please create a dump “dumpdata: true” and upload the file “lxd_data- .atd” and the config.

I am currently primarily interested in the results of the test with clusters and a “location” and “vlanid”.

Greetings Frank

2 Likes

Oh, that sounds quite interesting!

Really of topic but i cant seem to connect to the containers when useing this inventory file.

Cant seem to set the

vars:
ansible_connection: lxd
ansible_user: root
ansible_become: no
ansible_lxd_remote: local

for the containers. Kinda new to ansible so prob just basic stuff im overlooking.

@conloos or anybody Could you please provide some examples of how to use this project in a playbook or in general how to use this? I’m new to ansible and would really like to try it out! Thank you.

Never mind, I found a good example here: https://github.com/ansible-collections/community.general/issues/4851

echo “plugin: community.general.lxd
state: RUNNING” > lxd.yml

ansible-inventory -i lxd.yml --list

Hi mcaddon,

in the Plugin are several examples included. This example are rendered to the documentation.

Thanks Frank

1 Like