Ansible with LXD module: UNREACHABLE: Error: Instance not found

Hello :wave:

I followed the @stgraber howto here: LXD and Ansible - YouTube (which works fine)

In my case I have the same hosts.yml code as stephane BUT with an extra definition recommended by redhat on their ansible best practices. That is also usefull when using the ansible_connection: ssh instead the ansible_connection: lxd in the same playbook.

My hosts.yml is:

---

all:
  vars:
    ansible_python_interpreter: /usr/bin/python3
    ansible_connection: lxd
    ansible_user: root
    ansible_become: no
  children:
    local:
      vars:
        ansible_lxd_remote: local
        ansible_lxd_project: default
      hosts:
        c1:
          ansible_host: 10.0.1.2

In this case the ansible-playbook command failed. I have fixed this problem after I readed a same problem here: When using the `lxd` connection module, all tasks fail with `"unreachable": true` · Issue #65831 · ansible/ansible · GitHub

I have fixed that by using the ansible_host: c1 directly on all tasks in my playbook that use the ansible_connection: lxd. This override the ansible_host: 10.0.1.2 in the hosts.yml (used for ansible_connection: ssh later in my playbook)

I hope this feedback will be usefull…

1 Like

Late reply, Might not work but give this a try, anyone reading this

Just made this account to say BIG THANK YOU to ZeroGravitas. YOU ARE SO AWESOME i was having trouble with:
"Ansible_loop_var attribute error: nonetype object has no attribute items" leading to lxd_container " error when installing xroad using ansible playbook

Here’s the log

line 99, in _ansiballz_main invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/vboxuser/.ansible/tmp/ansible-tmp-1728036128.1841958-3528-12931979 1180256/Ansiballz_lxd_container.py", line 47, in invoke_module runpy.run_module(mod_name='ansible_collections.community.general.plugins.mod
ules.lxd_container', init_globals-dict(_module_fqn='ansible_collections.communit y.general.plugins.modules.lxd_container', _modlib_path=modlib_path), File "/usr/lib/python3.10/runpy.py", line 224, in run_module return _run_module_code(code, init_globals, run_name, mod_spec) File "/usr/lib/python3.10/runpy.py", line 96, in _run_module_code _run_code(code, mod_globals, init_globals,
File "/usr/lib/python3.10/runpy.py", line 86, in _run_code exec(code, run_globals)
File "/tmp/ansible_lxd_container_payload_g1eotpsb/ansible_lxd_container_payloa d.zip/ansible_collections/community/general/plugins/modules/lxd_container.py", l ine 901, in <module>

All that was needed was:

ansible-galaxy collection install community.general -f

THANK YOU SO VERY MUCH. YOU ARE AN AMAZING INDIVIDUAL