Sadly, the version of ansible which is in the main repository has skewed from that of the official release. I noticed the the loader.py file which is part of our installed ansible (/usr/local/lib/python3.10/dist-packages/ansible/plugins/loader.py) differs to that of the one in the ansible source code that we cloned (/home/ansible/ansible/lib/ansible/plugins/loader.py)
When we run the test module (~/ansible/hacking/test-module) it is using the loader.py from our installed ansible version (/usr/local/lib/python3.10/dist-packages/ansible/plugins/loader.py) instead of the one in the source tree (/home/ansible/ansible/lib/ansible/plugins/loader.py) -- although this is annoying it is expected behaviour in Python, it will and should search installed paths first.
The way to fix this, we need to ensure that the ansible source code that we're using, matches our version of ansible. So for now, the instructions for this class need to be updated as follows -
# find out the ansible core version
ansible@ubuntu-c:~$ ansible --version
ansible [core 2.14.2] <----- *** Release 2.14 ***
config file = None
configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible
ansible collection location = /home/ansible/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] (/usr/bin/python3)
jinja version = 3.1.2
libyaml = True
# clone the ansible source code to ~
cd ~
git clone https://github.com/ansible/ansible.git
# checkout a specific branch, this should match the release in ansible --version
cd ansible
# show available branches
ansible@ubuntu-c:~/ansible$ git fetch -v
POST git-upload-pack (155 bytes)
From https://github.com/ansible/ansible
= [up to date] devel -> origin/devel
= [up to date] mazer_role_loader -> origin/mazer_role_loader
= [up to date] milestone -> origin/milestone
= [up to date] release1.5.0 -> origin/release1.5.0
= [up to date] release1.5.1 -> origin/release1.5.1
= [up to date] release1.5.2 -> origin/release1.5.2
= [up to date] release1.5.3 -> origin/release1.5.3
= [up to date] release1.5.4 -> origin/release1.5.4
= [up to date] release1.5.5 -> origin/release1.5.5
= [up to date] release1.6.0 -> origin/release1.6.0
= [up to date] release1.6.1 -> origin/release1.6.1
= [up to date] release1.6.10 -> origin/release1.6.10
= [up to date] release1.6.2 -> origin/release1.6.2
= [up to date] release1.6.3 -> origin/release1.6.3
= [up to date] release1.6.4 -> origin/release1.6.4
= [up to date] release1.6.5 -> origin/release1.6.5
= [up to date] release1.6.6 -> origin/release1.6.6
= [up to date] release1.6.7 -> origin/release1.6.7
= [up to date] release1.6.8 -> origin/release1.6.8
= [up to date] release1.6.9 -> origin/release1.6.9
= [up to date] release1.7.0 -> origin/release1.7.0
= [up to date] release1.7.1 -> origin/release1.7.1
= [up to date] release1.7.2 -> origin/release1.7.2
= [up to date] release1.8.0 -> origin/release1.8.0
= [up to date] release1.8.1 -> origin/release1.8.1
= [up to date] release1.8.2 -> origin/release1.8.2
= [up to date] release1.8.3 -> origin/release1.8.3
= [up to date] release1.8.4 -> origin/release1.8.4
= [up to date] stable-1.9 -> origin/stable-1.9
= [up to date] stable-2.0 -> origin/stable-2.0
= [up to date] stable-2.0-network -> origin/stable-2.0-network
= [up to date] stable-2.0.0.1 -> origin/stable-2.0.0.1
= [up to date] stable-2.1 -> origin/stable-2.1
= [up to date] stable-2.10 -> origin/stable-2.10
= [up to date] stable-2.11 -> origin/stable-2.11
= [up to date] stable-2.12 -> origin/stable-2.12
= [up to date] stable-2.13 -> origin/stable-2.13
= [up to date] stable-2.14 -> origin/stable-2.14
= [up to date] stable-2.15 -> origin/stable-2.15
= [up to date] stable-2.2 -> origin/stable-2.2
= [up to date] stable-2.3 -> origin/stable-2.3
= [up to date] stable-2.4 -> origin/stable-2.4
= [up to date] stable-2.5 -> origin/stable-2.5
= [up to date] stable-2.6 -> origin/stable-2.6
= [up to date] stable-2.7 -> origin/stable-2.7
= [up to date] stable-2.8 -> origin/stable-2.8
= [up to date] stable-2.9 -> origin/stable-2.9
= [up to date] temp-2.10-devel -> origin/temp-2.10-devel
= [up to date] threading_instead_of_forking -> origin/threading_instead_of_forking
= [up to date] threading_plus_forking -> origin/threading_plus_forking
# switch to the stable version of that branch
git checkout stable-2.14
# test the test-module (we're running this with python3 direct, change the interpreter to avoid doing this each time)
python3 ~/ansible/hacking/test-module
Usage: test-module -[options] (-h for help)
Options:
-h, --help show this help message and exit
-m MODULE_PATH, --module-path=MODULE_PATH
REQUIRED: full path of module source to execute
-a MODULE_ARGS, --args=MODULE_ARGS
module argument string
-D DEBUGGER, --debugger=DEBUGGER
path to python debugger (e.g. /usr/bin/pdb)
-I INTERPRETER_TYPE=INTERPRETER_PATH, --interpreter=INTERPRETER_TYPE=INTERPRETER_PATH
path to interpreter to use for this module (e.g.
ansible_python_interpreter=/usr/bin/python)
-c, --check run the module in check mode
-n, --noexecute do not run the resulting module
-o FILENAME, --output=FILENAME
Filename for resulting module