How to fix Ansible with LXD error "Ansible_loop_var attribute error: nonetype object has no attribute items" leading to lxd_container.py"

I was struggling with Ansible trying to install Xroad for a few days here’s the log:

<localhost> EXEC /bin/sh -c 'rm -f -r /home/vboxuser/.ansible/tmp/ansible-tmp-17 28036128.1841958-3528-129319791180256/> /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/home/vboxuser/.ansible/tmp/ansible-tmp-1728036128.1841958-3528-12931979 1180256/Ansiballz_lxd_container.py", line 107, in <module>
_ansiballz_main()
File "/home/vboxuser/.ansible/tmp/ansible-tmp-1728036128.1841958-3528-12931979 1180256/Ansiballz_lxd_container.py", 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>

My steps were:

sudo snap install lxd
newgrp lxd
sudo lxd init

sudo apt update
sudo apt install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install ansible

ansible-playbook -i hosts/lxd_hosts.txt xroad_init.yml

First time i did the steps above, i didnt have any problems at all but 2nd time and later, all fails.

Turns out, all it was needed was:

ansible-galaxy collection install community.general -f