fortinet-ansible-dev / ansible-galaxy-fortios-collection

GNU General Public License v3.0
85 stars 49 forks source link

fortios_facts is broken in 1.1.4 #82

Closed JonTheNiceGuy closed 3 years ago

JonTheNiceGuy commented 3 years ago

Given the following scenario:

When the following play is run:

---
- hosts: all
  gather_facts: false
  tasks:
  - name: Get HA Status
    fortinet.fortios.fortios_facts:
      gather_subset:
        - fact: system_ha-checksums_select

The following result is seen (using -vvvvvv)

(Ansible-2.10.3) spriggsj@G02UKXN10810:/mnt/c/Users/SPRIGGSJ/Documents/01 Projects/2020-12-16 Test Failing Ansible-FortiOS Modules$ ansible-playbook fortios_facts.yml -vvvvvv
ansible-playbook 2.10.3
  config file = /mnt/c/Users/SPRIGGSJ/Documents/01 Projects/2020-12-16 Test Failing Ansible-FortiOS Modules/ansible.cfg
  configured module search path = ['/home/spriggsj/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/spriggsj/Ansible-2.10.3/lib/python3.8/site-packages/ansible
  executable location = /home/spriggsj/Ansible-2.10.3/bin/ansible-playbook
  python version = 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0]
Using /mnt/c/Users/SPRIGGSJ/Documents/01 Projects/2020-12-16 Test Failing Ansible-FortiOS Modules/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /mnt/c/Users/SPRIGGSJ/Documents/01 Projects/2020-12-16 Test Failing Ansible-FortiOS Modules/inventory as it did not pass its verify_file() method
script declined parsing /mnt/c/Users/SPRIGGSJ/Documents/01 Projects/2020-12-16 Test Failing Ansible-FortiOS Modules/inventory as it did not pass its verify_file() method
auto declined parsing /mnt/c/Users/SPRIGGSJ/Documents/01 Projects/2020-12-16 Test Failing Ansible-FortiOS Modules/inventory as it did not pass its verify_file() method
Parsed /mnt/c/Users/SPRIGGSJ/Documents/01 Projects/2020-12-16 Test Failing Ansible-FortiOS Modules/inventory inventory source with ini plugin
Loading collection fortinet.fortios from /mnt/c/Users/SPRIGGSJ/Documents/01 Projects/2020-12-16 Test Failing Ansible-FortiOS Modules/collections/ansible_collections/fortinet/fortios
Loading callback plugin default of type stdout, v2.0 from /home/spriggsj/Ansible-2.10.3/lib/python3.8/site-packages/ansible/plugins/callback/default.py
Attempting to use 'default' callback.
Skipping callback 'default', as we already have a stdout callback.
Attempting to use 'junit' callback.
Attempting to use 'minimal' callback.
Skipping callback 'minimal', as we already have a stdout callback.
Attempting to use 'oneline' callback.
Skipping callback 'oneline', as we already have a stdout callback.
Attempting to use 'tree' callback.

PLAYBOOK: fortios_facts.yml ********************************************************************************************************************************
Positional arguments: fortios_facts.yml
verbosity: 6
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/mnt/c/Users/SPRIGGSJ/Documents/01 Projects/2020-12-16 Test Failing Ansible-FortiOS Modules/inventory',)
forks: 5
1 plays in fortios_facts.yml

PLAY [all] *************************************************************************************************************************************************
META: ran handlers
redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi
Loading collection ansible.netcommon from /mnt/c/Users/SPRIGGSJ/Documents/01 Projects/2020-12-16 Test Failing Ansible-FortiOS Modules/collections/ansible_collections/ansible/netcommon
<fw-a.example.org> attempting to start connection
<fw-a.example.org> using connection plugin ansible.netcommon.httpapi
Found ansible-connection at path /home/spriggsj/Ansible-2.10.3/bin/ansible-connection
<fw-a.example.org> local domain socket does not exist, starting it
<fw-a.example.org> control socket path is /home/spriggsj/.ansible/pc/f854a6e201
<fw-a.example.org> redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi
<fw-a.example.org> Loading collection ansible.netcommon from /mnt/c/Users/SPRIGGSJ/Documents/01 Projects/2020-12-16 Test Failing Ansible-FortiOS Modules/collections/ansible_collections/ansible/netcommon
<fw-a.example.org> Loading collection fortinet.fortios from /mnt/c/Users/SPRIGGSJ/Documents/01 Projects/2020-12-16 Test Failing Ansible-FortiOS Modules/collections/ansible_collections/fortinet/fortios
<fw-a.example.org> local domain socket listeners started successfully
<fw-a.example.org> loaded API plugin ansible_collections.fortinet.fortios.plugins.httpapi.fortios from path /mnt/c/Users/SPRIGGSJ/Documents/01 Projects/2020-12-16 Test Failing Ansible-FortiOS Modules/collections/ansible_collections/fortinet/fortios/plugins/httpapi/fortios.py for network_os fortinet.fortios.fortios
<fw-a.example.org> 
<fw-a.example.org> local domain socket path is /home/spriggsj/.ansible/pc/f854a6e201
<fw-a.example.org> ESTABLISH LOCAL CONNECTION FOR USER: spriggsj
<fw-a.example.org> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/spriggsj/.ansible/tmp/ansible-local-27234my372ijd `"&& mkdir "` echo /home/spriggsj/.ansible/tmp/ansible-local-27234my372ijd/ansible-tmp-1608116816.7522142-27244-79931496865622 `" && echo ansible-tmp-1608116816.7522142-27244-79931496865622="` echo /home/spriggsj/.ansible/tmp/ansible-local-27234my372ijd/ansible-tmp-1608116816.7522142-27244-79931496865622 `" ) && sleep 0'
redirecting module_util ansible.module_utils.network.common.facts.facts to ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts
redirecting module_util ansible.module_utils.network.common.utils to ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils
Including module_utils file ansible/__init__.py
Including module_utils file ansible/module_utils/__init__.py
Including module_utils file ansible/module_utils/basic.py
Including module_utils file ansible/module_utils/_text.py
Including module_utils file ansible/module_utils/common/_collections_compat.py
Including module_utils file ansible/module_utils/common/__init__.py
Including module_utils file ansible/module_utils/common/_json_compat.py
Including module_utils file ansible/module_utils/common/_utils.py
Including module_utils file ansible/module_utils/common/file.py
Including module_utils file ansible/module_utils/common/parameters.py
Including module_utils file ansible/module_utils/common/collections.py
Including module_utils file ansible/module_utils/common/process.py
Including module_utils file ansible/module_utils/common/sys_info.py
Including module_utils file ansible/module_utils/common/text/converters.py
Including module_utils file ansible/module_utils/common/text/__init__.py
Including module_utils file ansible/module_utils/common/text/formatters.py
Including module_utils file ansible/module_utils/common/validation.py
Including module_utils file ansible/module_utils/common/warnings.py
Including module_utils file ansible/module_utils/compat/selectors.py
Including module_utils file ansible/module_utils/compat/__init__.py
Including module_utils file ansible/module_utils/compat/_selectors2.py
Including module_utils file ansible/module_utils/connection.py
Including module_utils file ansible/module_utils/common/json.py
Including module_utils file ansible/module_utils/distro/__init__.py
Including module_utils file ansible/module_utils/distro/_distro.py
Including module_utils file ansible/module_utils/parsing/convert_bool.py
Including module_utils file ansible/module_utils/parsing/__init__.py
Including module_utils file ansible/module_utils/pycompat24.py
Including module_utils file ansible/module_utils/six/__init__.py
Including module_utils file ansible_collections/fortinet/fortios/plugins/module_utils/fortimanager/common.py
Including module_utils file ansible_collections/__init__.py
Including module_utils file ansible_collections/fortinet/__init__.py
Including module_utils file ansible_collections/fortinet/fortios/__init__.py
Including module_utils file ansible_collections/fortinet/fortios/plugins/__init__.py
Including module_utils file ansible_collections/fortinet/fortios/plugins/module_utils/__init__.py
Including module_utils file ansible_collections/fortinet/fortios/plugins/module_utils/fortimanager/__init__.py
Including module_utils file ansible_collections/fortinet/fortios/plugins/module_utils/fortios/argspec/facts/facts.py
Including module_utils file ansible_collections/fortinet/fortios/plugins/module_utils/fortios/__init__.py
Including module_utils file ansible_collections/fortinet/fortios/plugins/module_utils/fortios/argspec/__init__.py
Including module_utils file ansible_collections/fortinet/fortios/plugins/module_utils/fortios/argspec/facts/__init__.py
Including module_utils file ansible_collections/fortinet/fortios/plugins/module_utils/fortios/facts/facts.py
Including module_utils file ansible/module_utils/network/common/facts/facts/__init__.py
Including module_utils file ansible/module_utils/network/__init__.py
Including module_utils file ansible/module_utils/network/common/__init__.py
Including module_utils file ansible/module_utils/network/common/facts/__init__.py
Including module_utils file ansible_collections/ansible/netcommon/plugins/module_utils/network/common/facts/facts.py
Including module_utils file ansible_collections/ansible/__init__.py
Including module_utils file ansible_collections/ansible/netcommon/__init__.py
Including module_utils file ansible_collections/ansible/netcommon/plugins/__init__.py
Including module_utils file ansible_collections/ansible/netcommon/plugins/module_utils/__init__.py
Including module_utils file ansible_collections/ansible/netcommon/plugins/module_utils/network/__init__.py
Including module_utils file ansible_collections/ansible/netcommon/plugins/module_utils/network/common/__init__.py
Including module_utils file ansible_collections/ansible/netcommon/plugins/module_utils/network/common/facts/__init__.py
Including module_utils file ansible_collections/ansible/netcommon/plugins/module_utils/network/common/network.py
Including module_utils file ansible_collections/ansible/netcommon/plugins/module_utils/network/common/netconf.py
Including module_utils file ansible_collections/ansible/netcommon/plugins/module_utils/network/common/parsing.py
Including module_utils file ansible_collections/ansible/netcommon/plugins/module_utils/network/common/utils.py
Including module_utils file ansible/module_utils/common/network.py
Including module_utils file ansible_collections/fortinet/fortios/plugins/module_utils/fortios/argspec/system/system.py
Including module_utils file ansible_collections/fortinet/fortios/plugins/module_utils/fortios/argspec/system/__init__.py
Including module_utils file ansible_collections/fortinet/fortios/plugins/module_utils/fortios/facts/__init__.py
Including module_utils file ansible_collections/fortinet/fortios/plugins/module_utils/fortios/facts/system/system.py
Including module_utils file ansible/module_utils/network/common/utils/__init__.py
Including module_utils file ansible_collections/fortinet/fortios/plugins/module_utils/fortios/facts/system/__init__.py
Including module_utils file ansible_collections/fortinet/fortios/plugins/module_utils/fortios/fortios.py
Using module file /mnt/c/Users/SPRIGGSJ/Documents/01 Projects/2020-12-16 Test Failing Ansible-FortiOS Modules/collections/ansible_collections/fortinet/fortios/plugins/modules/fortios_facts.py
<fw-a.example.org> PUT /home/spriggsj/.ansible/tmp/ansible-local-27234my372ijd/tmp_xb_467q TO /home/spriggsj/.ansible/tmp/ansible-local-27234my372ijd/ansible-tmp-1608116816.7522142-27244-79931496865622/AnsiballZ_fortios_facts.py
<fw-a.example.org> EXEC /bin/sh -c 'chmod u+x /home/spriggsj/.ansible/tmp/ansible-local-27234my372ijd/ansible-tmp-1608116816.7522142-27244-79931496865622/ /home/spriggsj/.ansible/tmp/ansible-local-27234my372ijd/ansible-tmp-1608116816.7522142-27244-79931496865622/AnsiballZ_fortios_facts.py && sleep 0'
<fw-a.example.org> EXEC /bin/sh -c '/home/spriggsj/Ansible-2.10.3/bin/python /home/spriggsj/.ansible/tmp/ansible-local-27234my372ijd/ansible-tmp-1608116816.7522142-27244-79931496865622/AnsiballZ_fortios_facts.py && sleep 0'
<fw-a.example.org> EXEC /bin/sh -c 'rm -f -r /home/spriggsj/.ansible/tmp/ansible-local-27234my372ijd/ansible-tmp-1608116816.7522142-27244-79931496865622/ > /dev/null 2>&1 && sleep 0'

TASK [Get HA Status] ***************************************************************************************************************************************
task path: /mnt/c/Users/SPRIGGSJ/Documents/01 Projects/2020-12-16 Test Failing Ansible-FortiOS Modules/fortios_facts.yml:5
The full traceback is:
Traceback (most recent call last):
  File "/home/spriggsj/.ansible/tmp/ansible-local-27234my372ijd/ansible-tmp-1608116816.7522142-27244-79931496865622/AnsiballZ_fortios_facts.py", line 102, in <module>
    _ansiballz_main()
  File "/home/spriggsj/.ansible/tmp/ansible-local-27234my372ijd/ansible-tmp-1608116816.7522142-27244-79931496865622/AnsiballZ_fortios_facts.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/spriggsj/.ansible/tmp/ansible-local-27234my372ijd/ansible-tmp-1608116816.7522142-27244-79931496865622/AnsiballZ_fortios_facts.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.fortinet.fortios.plugins.modules.fortios_facts', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.8/runpy.py", line 207, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.8/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_fortinet.fortios.fortios_facts_payload_zmxqyfqw/ansible_fortinet.fortios.fortios_facts_payload.zip/ansible_collections/fortinet/fortios/plugins/modules/fortios_facts.py", line 281, in <module>
  File "/tmp/ansible_fortinet.fortios.fortios_facts_payload_zmxqyfqw/ansible_fortinet.fortios.fortios_facts_payload.zip/ansible_collections/fortinet/fortios/plugins/modules/fortios_facts.py", line 250, in main
TypeError: __init__() missing 1 required positional argument: 'mod'
fatal: [fw-a]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/spriggsj/.ansible/tmp/ansible-local-27234my372ijd/ansible-tmp-1608116816.7522142-27244-79931496865622/AnsiballZ_fortios_facts.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/home/spriggsj/.ansible/tmp/ansible-local-27234my372ijd/ansible-tmp-1608116816.7522142-27244-79931496865622/AnsiballZ_fortios_facts.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/spriggsj/.ansible/tmp/ansible-local-27234my372ijd/ansible-tmp-1608116816.7522142-27244-79931496865622/AnsiballZ_fortios_facts.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.fortinet.fortios.plugins.modules.fortios_facts', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_fortinet.fortios.fortios_facts_payload_zmxqyfqw/ansible_fortinet.fortios.fortios_facts_payload.zip/ansible_collections/fortinet/fortios/plugins/modules/fortios_facts.py\", line 281, in <module>\n  File \"/tmp/ansible_fortinet.fortios.fortios_facts_payload_zmxqyfqw/ansible_fortinet.fortios.fortios_facts_payload.zip/ansible_collections/fortinet/fortios/plugins/modules/fortios_facts.py\", line 250, in main\nTypeError: __init__() missing 1 required positional argument: 'mod'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

PLAY RECAP *************************************************************************************************************************************************
fw-a                       : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

This is a regression between 1.0.11 and 1.1.4, and is because there's a difference between module_utils/fortios/fortios.py in each, that looks like this:

94c94
<     def __init__(self, conn):
---
>     def __init__(self, conn, mod, module_mkeyname=None):
95a96,97
>         self._module = mod
>         self._mkeyname = module_mkeyname

This change was introduced here: https://github.com/fortinet-ansible-dev/fortios-ansible-generator/commit/0071ff75ad8c968a5bf2a4bbd8f30894d2f8ba48, but only appears to impact this one module (at least, without performing more robust testing!)

JonTheNiceGuy commented 3 years ago

It looks like it's been resolved in the devel/2.x branch of the generator.

If you hit this issue, until a release with a fix is produced, the adjustment is to look for line ~249 in $YourCollectionsPath/ansible_collections/fortinet/fortios/plugins/modules/fortios_facts.py, where it says fos = FortiOSHandler(connection) and change it to fos = FortiOSHandler(connection, module)

chillancezen commented 3 years ago

thank you Jon for the detailed troubleshooting.

fortios_facts is a legacy module, we team discussed about this module, we are going to fully deprecate this module in next major release as we are going to implement all monitor APIs which will cover the content of fortios_facts.

we are going to build a hot collection to fix it in 1.1.x in days.

thanks again. Link