PaloAltoNetworks / ansible-pan

Ansible modules for Palo Alto Networks NGFWs
Other
229 stars 161 forks source link

panos_object_facts.py doesn't honor "delegate_to" configuration #487

Closed ivazqueza closed 4 years ago

ivazqueza commented 4 years ago

When panos_object_facts.py is used with "delegate_to" it throws the error:

"NameError: name 'objects' is not defined"

Expected behavior

It should get the facts about the referenced object.

Current behavior

The following error raises:

The full traceback is:
Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-tmp-1590140360.7278438-240394145334822/AnsiballZ_panos_object_facts.py", line 102, in <module>
    _ansiballz_main()
  File "/root/.ansible/tmp/ansible-tmp-1590140360.7278438-240394145334822/AnsiballZ_panos_object_facts.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/root/.ansible/tmp/ansible-tmp-1590140360.7278438-240394145334822/AnsiballZ_panos_object_facts.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.paloaltonetworks.panos.plugins.modules.panos_object_facts', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.7/runpy.py", line 205, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_paloaltonetworks.panos.panos_object_facts_payload_i4cukjun/ansible_paloaltonetworks.panos.panos_object_facts_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_object_facts.py", line 276, in <module>
  File "/tmp/ansible_paloaltonetworks.panos.panos_object_facts_payload_i4cukjun/ansible_paloaltonetworks.panos.panos_object_facts_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_object_facts.py", line 189, in main
NameError: name 'objects' is not defined
fatal: [remote_host -> 127.0.0.1]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1590140360.7278438-240394145334822/AnsiballZ_panos_object_facts.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1590140360.7278438-240394145334822/AnsiballZ_panos_object_facts.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1590140360.7278438-240394145334822/AnsiballZ_panos_object_facts.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.paloaltonetworks.panos.plugins.modules.panos_object_facts', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib/python3.7/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.7/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/lib/python3.7/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_paloaltonetworks.panos.panos_object_facts_payload_i4cukjun/ansible_paloaltonetworks.panos.panos_object_facts_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_object_facts.py\", line 276, in <module>\n  File \"/tmp/ansible_paloaltonetworks.panos.panos_object_facts_payload_i4cukjun/ansible_paloaltonetworks.panos.panos_object_facts_payload.zip/ansible_collections/paloaltonetworks/panos/plugins/modules/panos_object_facts.py\", line 189, in main\nNameError: name 'objects' is not defined\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

Possible solution

Don't know

Steps to reproduce

Run the following playbook:

- name: Play
  hosts: remote_host
  gather_facts: yes
  tasks:
    - name: "Get the actual members of known groups"
      paloaltonetworks.panos.panos_object_facts:
        provider: "{{ palo_provider }}"
        object_type: "address-group"
        name: "example"
      register: result
      delegate_to: 127.0.0.1

Screenshots

None

Context

This error does not appear when using in the play:

connection: local 

However, it would be very interesting to be able to reference a remote host in order to have access to the facts and variables belonging to this host.

Your Environment

welcome[bot] commented 4 years ago

:tada: Thanks for opening your first issue here! Welcome to the community!

ivazqueza commented 4 years ago

It turns out that this was not a bug in "panos_object_facts.py" but the error was caused by a bad choice of the python interpreter.

Despite using connection:local, ansible sets the python interpreter by a discovery on the remote machine. Then the python interpreter was set to python3 but in the ansible host the only pandevice and pan-python packages are the python2 versions, which resulted in the described error (not very descriptive, actually).

There are two possible solutions. The first one is to install the pandevice and pan-python versions for python3 in the ansible host.

The second is to configure the "localhost" host in the inventory and set the variables for this host like this:

ansible_connection: local
ansible_python_interpreter: "/usr/bin/python"