ansible.netcommon
ansible.netcommon copied to clipboard
"Unmarshallable object" exception while used with dynamic inventories
SUMMARY
Latest released ansible.netcommon v6.0.0 produces exception when used with dynamic inventory (with group) created via "ansible.builtin.add_host"
ISSUE TYPE
- Bug Report
COMPONENT NAME
ansible.netcommon ansible.utils
ANSIBLE VERSION
ansible [core 2.16.3]
config file = /home/debian/ansible/ansible.cfg
configured module search path = ['/home/debian/ansible/library']
ansible python module location = /home/debian/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/debian/.ansible/collections:/usr/share/ansible/collections
executable location = /home/debian/.local/bin/ansible
python version = 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] (/home/debian/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.3
libyaml = True
COLLECTION VERSION
# /home/debian/.ansible/collections/ansible_collections
Collection Version
----------------- -------
ansible.netcommon 6.0.0
CONFIGURATION
CONFIG_FILE() = /home/debian/ansible/ansible.cfg
DEFAULT_FILTER_PLUGIN_PATH(/home/debian/ansible/ansible.cfg) = ['/home/debian/ansible/filter_plugins']
DEFAULT_HOST_LIST(/home/debian/ansible/ansible.cfg) = ['/home/debian/ansible/inventories/sit']
DEFAULT_LOAD_CALLBACK_PLUGINS(/home/debian/ansible/ansible.cfg) = True
DEFAULT_MODULE_PATH(/home/debian/ansible/ansible.cfg) = ['/home/debian/ansible/library']
DEFAULT_MODULE_UTILS_PATH(/home/debian/ansible/ansible.cfg) = ['/home/debian/ansible/module_utils']
DEFAULT_ROLES_PATH(/home/debian/ansible/ansible.cfg) = ['/home/debian/ansible/roles']
DEFAULT_STDOUT_CALLBACK(/home/debian/ansible/ansible.cfg) = yaml
DEFAULT_TIMEOUT(/home/debian/ansible/ansible.cfg) = 180
DEFAULT_VAULT_PASSWORD_FILE(/home/debian/ansible/ansible.cfg) = /home/debian/ansible_vault_password
HOST_KEY_CHECKING(/home/debian/ansible/ansible.cfg) = False
INVENTORY_ENABLED(/home/debian/ansible/ansible.cfg) = ['yaml']
OS / ENVIRONMENT
Debian 12
STEPS TO REPRODUCE
playbook
- name: Play1
strategy: linear
hosts: mytest
gather_facts: false
tasks:
- name: Print current inventory
ansible.builtin.debug:
var: ansible_play_hosts_all
- name: Add hosts to dynamic in-memory inventory
ansible.builtin.add_host:
name: "10.10.10.10"
ansible_user: login
ansible_port: 22
ansible_password: password
ansible_connection: ansible.netcommon.network_cli
ansible_network_os: cisco.ios.ios
groups: dynamic_group
- name: Play2
strategy: linear
hosts: dynamic_group
gather_facts: false
tasks:
- name: Print current inventory
ansible.builtin.debug:
var: ansible_play_hosts_all
inventory:
mytest:
hosts:
10.1.1.1:
ansible_user: developer
ansible_port: 22
ansible_become: true
ansible_become_method: sudo
EXPECTED RESULTS
PLAY [Play1] ***************************************************************************************************************************************************************************************************************************************************
TASK [Print current inventory] *********************************************************************************************************************************************************************************************************************************
ok: [10.189.100.1] =>
ansible_play_hosts_all:
- 10.189.100.1
TASK [Add hosts to dynamic in-memory inventory] ****************************************************************************************************************************************************************************************************************
changed: [10.189.100.1]
PLAY [Play2] ***************************************************************************************************************************************************************************************************************************************************
TASK [Print current inventory] *********************************************************************************************************************************************************************************************************************************
ok: [10.10.10.10] =>
ansible_play_hosts_all:
- 10.10.10.10
PLAY RECAP *****************************************************************************************************************************************************************************************************************************************************
10.10.10.10 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
10.189.100.1 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ACTUAL RESULTS
ansible-playbook [core 2.16.3]
config file = /home/debian/ansible/ansible.cfg
configured module search path = ['/home/debian/ansible/library']
ansible python module location = /home/debian/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible
ansible collection location = /home/debian/.ansible/collections:/usr/share/ansible/collections
executable location = /home/debian/.local/bin/ansible-playbook
python version = 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] (/home/debian/.local/pipx/venvs/ansible/bin/python)
jinja version = 3.1.3
libyaml = True
Using /home/debian/ansible/ansible.cfg as config file
setting up inventory plugins
Loading collection ansible.builtin from
Parsed /home/debian/ansible/inventories/sit/hosts inventory source with yaml plugin
setting up inventory plugins
Skipping empty key (hosts) in group (nd_dynamic)
Parsed /home/debian/ansible/inventories/sit/nd_dynamic inventory source with yaml plugin
redirecting (type: callback) ansible.builtin.yaml to community.general.yaml
Loading collection community.general from /home/debian/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible_collections/community/general
redirecting (type: callback) ansible.builtin.yaml to community.general.yaml
Loading callback plugin community.general.yaml of type stdout, v2.0 from /home/debian/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible_collections/community/general/plugins/callback/yaml.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
PLAYBOOK: test.yml *********************************************************************************************************************************************************************************************************************************************
Positional arguments: playbooks/test.yml
verbosity: 4
connection: ssh
become_method: sudo
tags: ('all',)
inventory: ('/home/debian/ansible/inventories/sit',)
forks: 5
2 plays in playbooks/test.yml
PLAY [Play1] ***************************************************************************************************************************************************************************************************************************************************
Trying secret FileVaultSecret(filename='/home/debian/ansible_vault_password') for vault_id=default
TASK [Print current inventory] *********************************************************************************************************************************************************************************************************************************
task path: /home/debian/ansible/playbooks/test.yml:10
ok: [10.189.100.1] =>
ansible_play_hosts_all:
- 10.189.100.1
TASK [Add hosts to dynamic in-memory inventory] ****************************************************************************************************************************************************************************************************************
task path: /home/debian/ansible/playbooks/test.yml:14
creating host via 'add_host': hostname=10.10.10.10
changed: [10.189.100.1] => changed=true
add_host:
groups:
- dynamic_group
host_name: 10.10.10.10
host_vars:
ansible_connection: ansible.netcommon.network_cli
ansible_network_os: cisco.ios.ios
ansible_password: password
ansible_port: 22
ansible_user: login
PLAY [Play2] ***************************************************************************************************************************************************************************************************************************************************
TASK [Print current inventory] *********************************************************************************************************************************************************************************************************************************
task path: /home/debian/ansible/playbooks/test.yml:31
Loading collection ansible.netcommon from /home/debian/.ansible/collections/ansible_collections/ansible/netcommon
The full traceback is:
Traceback (most recent call last):
File "/home/debian/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/executor/task_executor.py", line 165, in run
res = self._execute()
^^^^^^^^^^^^^^^
File "/home/debian/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/executor/task_executor.py", line 574, in _execute
self._connection = self._get_connection(cvars, templar, current_connection)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/debian/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/executor/task_executor.py", line 953, in _get_connection
connection, plugin_load_context = self._shared_loader_obj.connection_loader.get_with_context(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/debian/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/loader.py", line 899, in get_with_context
self._module_cache[path] = self._load_module_source(resolved_type_name, path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/debian/.local/pipx/venvs/ansible/lib/python3.11/site-packages/ansible/plugins/loader.py", line 837, in _load_module_source
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 936, in exec_module
File "<frozen importlib._bootstrap_external>", line 1083, in get_code
File "<frozen importlib._bootstrap_external>", line 746, in _code_to_timestamp_pyc
ValueError: unmarshallable object
fatal: [10.10.10.10]: FAILED! =>
msg: 'Unexpected failure during module execution: unmarshallable object'
PLAY RECAP *****************************************************************************************************************************************************************************************************************************************************
10.10.10.10 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
10.189.100.1 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Reverting back to ansible.netcommon v5.3.0 fixes the issue completely.