hetzner.hcloud icon indicating copy to clipboard operation
hetzner.hcloud copied to clipboard

Cannot get networking info when there is an attached server without ipv4

Open ausias-armesto opened this issue 3 years ago • 1 comments
trafficstars

SUMMARY

The hcloud_network_infomodule is not taking into consideration the possibility that you have in your network servers with local ip only, and not having a public ipv4 assigned. I've checked that the component is working when I execute the component in a network where all its servers have public ipv4.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

The affected component is hcloud_network_info

ANSIBLE VERSION
ansible [core 2.13.2]
  config file = /Users/ausias/Documents/github/hopr-devops/ansible/ansible.cfg
  configured module search path = ['/Users/ausias/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/Cellar/ansible/6.2.0/libexec/lib/python3.10/site-packages/ansible
  ansible collection location = /Users/ausias/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible
  python version = 3.10.6 (main, Aug 30 2022, 04:58:14) [Clang 13.1.6 (clang-1316.0.21.2.5)]
  jinja version = 3.1.2
  libyaml = True

COLLECTION VERSION
# /Users/ausias/.ansible/collections/ansible_collections
Collection     Version
-------------- -------
hetzner.hcloud 1.8.1  

# /opt/homebrew/Cellar/ansible/6.2.0/libexec/lib/python3.10/site-packages/ansible_collections
Collection     Version
-------------- -------
hetzner.hcloud 1.8.1  
CONFIGURATION
DEFAULT_ROLES_PATH(/Users/ausias/Documents/github/hopr-devops/ansible/ansible.cfg) = ['/Users/ausias/.ansible/roles', '/Users/ausias/Documents/github/ansible-roles']
HOST_KEY_CHECKING(/Users/ausias/Documents/github/hopr-devops/ansible/ansible.cfg) = False
OS / ENVIRONMENT

Not relevant

STEPS TO REPRODUCE
  • Connect to HCloud console
  • Create a Network
  • Create a subnet
  • Create a server without public IPv4 and attach it to previous subnet
  • Execute the following playbook
- name: "Get Hcloud networking"
  hosts: localhost
  gather_facts: false
  tasks:      
    - name: "Gather networks info"
      hetzner.hcloud.hcloud_network_info:
         api_token: XXXXXXXXXXXX
      delegate_to: localhost
EXPECTED RESULTS

I expect the task to finish correctly without raising an error and showing the information

ACTUAL RESULTS

The task fails with the following stacktrace:

TASK [Gather networks info] ****************************************************
task path: /Users/ausias/Documents/github/hopr-devops/ansible/playbooks/hetzner/network.yaml:15
redirecting (type: modules) ansible.builtin.hcloud_network_info to hetzner.hcloud.hcloud_network_info
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: ausias
<localhost> EXEC /bin/sh -c 'echo ~ausias && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /Users/ausias/.ansible/tmp `"&& mkdir "` echo /Users/ausias/.ansible/tmp/ansible-tmp-1664451802.70404-86778-148411151466311 `" && echo ansible-tmp-1664451802.70404-86778-148411151466311="` echo /Users/ausias/.ansible/tmp/ansible-tmp-1664451802.70404-86778-148411151466311 `" ) && sleep 0'
redirecting (type: modules) ansible.builtin.hcloud_network_info to hetzner.hcloud.hcloud_network_info
Using module file /Users/ausias/.ansible/collections/ansible_collections/hetzner/hcloud/plugins/modules/hcloud_network_info.py
<localhost> PUT /Users/ausias/.ansible/tmp/ansible-local-86770tzp56smv/tmp_40pufdc TO /Users/ausias/.ansible/tmp/ansible-tmp-1664451802.70404-86778-148411151466311/AnsiballZ_hcloud_network_info.py
<localhost> EXEC /bin/sh -c 'chmod u+x /Users/ausias/.ansible/tmp/ansible-tmp-1664451802.70404-86778-148411151466311/ /Users/ausias/.ansible/tmp/ansible-tmp-1664451802.70404-86778-148411151466311/AnsiballZ_hcloud_network_info.py && sleep 0'
<localhost> EXEC /bin/sh -c '/opt/homebrew/Cellar/ansible/6.2.0/libexec/bin/python3.10 /Users/ausias/.ansible/tmp/ansible-tmp-1664451802.70404-86778-148411151466311/AnsiballZ_hcloud_network_info.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /Users/ausias/.ansible/tmp/ansible-tmp-1664451802.70404-86778-148411151466311/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/Users/ausias/.ansible/tmp/ansible-tmp-1664451802.70404-86778-148411151466311/AnsiballZ_hcloud_network_info.py", line 107, in <module>
    _ansiballz_main()
  File "/Users/ausias/.ansible/tmp/ansible-tmp-1664451802.70404-86778-148411151466311/AnsiballZ_hcloud_network_info.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/Users/ausias/.ansible/tmp/ansible-tmp-1664451802.70404-86778-148411151466311/AnsiballZ_hcloud_network_info.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.hetzner.hcloud.plugins.modules.hcloud_network_info', init_globals=dict(_module_fqn='ansible_collections.hetzner.hcloud.plugins.modules.hcloud_network_info', _modlib_path=modlib_path),
  File "/opt/homebrew/Cellar/[email protected]/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 224, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/opt/homebrew/Cellar/[email protected]/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/opt/homebrew/Cellar/[email protected]/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/var/folders/r6/qtb6n2vn5cx6b8kp93nbz5tw0000gn/T/ansible_hcloud_network_info_payload_mamz0hgw/ansible_hcloud_network_info_payload.zip/ansible_collections/hetzner/hcloud/plugins/modules/hcloud_network_info.py", line 296, in <module>
  File "/var/folders/r6/qtb6n2vn5cx6b8kp93nbz5tw0000gn/T/ansible_hcloud_network_info_payload_mamz0hgw/ansible_hcloud_network_info_payload.zip/ansible_collections/hetzner/hcloud/plugins/modules/hcloud_network_info.py", line 288, in main
  File "/var/folders/r6/qtb6n2vn5cx6b8kp93nbz5tw0000gn/T/ansible_hcloud_network_info_payload_mamz0hgw/ansible_hcloud_network_info_payload.zip/ansible_collections/hetzner/hcloud/plugins/module_utils/hcloud.py", line 63, in get_result
  File "/var/folders/r6/qtb6n2vn5cx6b8kp93nbz5tw0000gn/T/ansible_hcloud_network_info_payload_mamz0hgw/ansible_hcloud_network_info_payload.zip/ansible_collections/hetzner/hcloud/plugins/modules/hcloud_network_info.py", line 226, in _prepare_result
AttributeError: 'NoneType' object has no attribute 'ip'
fatal: [vm-stage-bastion-01 -> localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/Users/ausias/.ansible/tmp/ansible-tmp-1664451802.70404-86778-148411151466311/AnsiballZ_hcloud_network_info.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/Users/ausias/.ansible/tmp/ansible-tmp-1664451802.70404-86778-148411151466311/AnsiballZ_hcloud_network_info.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/ausias/.ansible/tmp/ansible-tmp-1664451802.70404-86778-148411151466311/AnsiballZ_hcloud_network_info.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.hetzner.hcloud.plugins.modules.hcloud_network_info', init_globals=dict(_module_fqn='ansible_collections.hetzner.hcloud.plugins.modules.hcloud_network_info', _modlib_path=modlib_path),\n  File \"/opt/homebrew/Cellar/[email protected]/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py\", line 224, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/opt/homebrew/Cellar/[email protected]/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py\", line 96, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/opt/homebrew/Cellar/[email protected]/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py\", line 86, in _run_code\n    exec(code, run_globals)\n  File \"/var/folders/r6/qtb6n2vn5cx6b8kp93nbz5tw0000gn/T/ansible_hcloud_network_info_payload_mamz0hgw/ansible_hcloud_network_info_payload.zip/ansible_collections/hetzner/hcloud/plugins/modules/hcloud_network_info.py\", line 296, in <module>\n  File \"/var/folders/r6/qtb6n2vn5cx6b8kp93nbz5tw0000gn/T/ansible_hcloud_network_info_payload_mamz0hgw/ansible_hcloud_network_info_payload.zip/ansible_collections/hetzner/hcloud/plugins/modules/hcloud_network_info.py\", line 288, in main\n  File \"/var/folders/r6/qtb6n2vn5cx6b8kp93nbz5tw0000gn/T/ansible_hcloud_network_info_payload_mamz0hgw/ansible_hcloud_network_info_payload.zip/ansible_collections/hetzner/hcloud/plugins/module_utils/hcloud.py\", line 63, in get_result\n  File \"/var/folders/r6/qtb6n2vn5cx6b8kp93nbz5tw0000gn/T/ansible_hcloud_network_info_payload_mamz0hgw/ansible_hcloud_network_info_payload.zip/ansible_collections/hetzner/hcloud/plugins/modules/hcloud_network_info.py\", line 226, in _prepare_result\nAttributeError: 'NoneType' object has no attribute 'ip'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

After reviewing the code I can see that there is no management of null or empty values for IPv4

                        "id": to_native(server.id),
                        "name": to_native(server.name),
                        "ipv4_address": to_native(server.public_net.ipv4.ip),
                        "ipv6": to_native(server.public_net.ipv6.ip),
                        "image": image,

This problem might happen as well for ipv6.

ausias-armesto avatar Sep 29 '22 12:09 ausias-armesto

got the same issue, this is really a dealbreaker.....always something breaks with hetzner......

medicol69 avatar Oct 04 '22 11:10 medicol69

Anything new here?

dcardellino avatar Nov 04 '22 11:11 dcardellino

Anything new here?

PR is open, waiting for someone to approve it.

Galaxy102 avatar Nov 04 '22 17:11 Galaxy102