ansible-collections / hetzner.hcloud

A collection to manage resources on Hetzner Cloud
https://galaxy.ansible.com/ui/repo/published/hetzner/hcloud
GNU General Public License v3.0
105 stars 37 forks source link

usage of hcloud_rdns results in warning and error #98

Closed markuman closed 3 years ago

markuman commented 3 years ago
SUMMARY

using hetzner.hcloud.hcloud_server.hcloud_rdns results first in a warning

[WARNING]: Collection ansible.netcommon does not support Ansible version 2.11.2

and second, in an error.

AttributeError: 'NoneType' object has no attribute 'public_net'

Full traceback is below.

ISSUE TYPE
COMPONENT NAME

hcloud_rdns

ANSIBLE VERSION
$ ansible --version
ansible [core 2.11.2] 
  config file = /home/m/git/osuv/ansible.cfg
  configured module search path = ['/home/m/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/m/.local/lib/python3.9/site-packages/ansible
  ansible collection location = /home/m/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/m/.local/bin/ansible
  python version = 3.9.6 (default, Jun 30 2021, 10:22:16) [GCC 11.1.0]
  jinja version = 3.0.1
  libyaml = True
COLLECTION VERSION
$ ansible-galaxy collection list

# /home/m/.local/lib/python3.9/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    1.5.0  
ansible.netcommon             2.2.0  
ansible.posix                 1.2.0  
ansible.utils                 2.3.0  
ansible.windows               1.7.0  
arista.eos                    2.2.0  
awx.awx                       19.2.2 
azure.azcollection            1.7.0  
check_point.mgmt              2.0.0  
chocolatey.chocolatey         1.1.0  
cisco.aci                     2.0.0  
cisco.asa                     2.0.2  
cisco.intersight              1.0.15 
cisco.ios                     2.3.0  
cisco.iosxr                   2.3.0  
cisco.meraki                  2.4.2  
cisco.mso                     1.2.0  
cisco.nso                     1.0.3  
cisco.nxos                    2.4.0  
cisco.ucs                     1.6.0  
cloudscale_ch.cloud           2.2.0  
community.aws                 1.5.0  
community.azure               1.0.0  
community.crypto              1.7.1  
community.digitalocean        1.7.0  
community.docker              1.8.0  
community.fortios             1.0.0  
community.general             3.3.0  
community.google              1.0.0  
community.grafana             1.2.1  
community.hashi_vault         1.3.0  
community.hrobot              1.1.1  
community.kubernetes          1.2.1  
community.kubevirt            1.0.0  
community.libvirt             1.0.1  
community.mongodb             1.2.1  
community.mysql               2.1.0  
community.network             3.0.0  
community.okd                 1.1.2  
community.postgresql          1.3.0  
community.proxysql            1.0.0  
community.rabbitmq            1.0.3  
community.routeros            1.2.0  
community.skydive             1.0.0  
community.sops                1.1.0  
community.vmware              1.11.0 
community.windows             1.5.0  
community.zabbix              1.3.0  
containers.podman             1.6.1  
cyberark.conjur               1.1.0  
cyberark.pas                  1.0.7  
dellemc.enterprise_sonic      1.1.0  
dellemc.openmanage            3.5.0  
dellemc.os10                  1.1.1  
dellemc.os6                   1.0.7  
dellemc.os9                   1.0.4  
f5networks.f5_modules         1.10.1 
fortinet.fortimanager         2.1.2  
fortinet.fortios              2.1.1  
frr.frr                       1.0.3  
gluster.gluster               1.0.1  
google.cloud                  1.0.2  
hetzner.hcloud                1.4.3  
hpe.nimble                    1.1.3  
ibm.qradar                    1.0.3  
infinidat.infinibox           1.2.4  
inspur.sm                     1.2.0  
junipernetworks.junos         2.3.0  
kubernetes.core               1.2.1  
mellanox.onyx                 1.0.0  
netapp.aws                    21.2.0 
netapp.azure                  21.7.0 
netapp.cloudmanager           21.7.0 
netapp.elementsw              21.6.1 
netapp.ontap                  21.7.0 
netapp.um_info                21.6.0 
netapp_eseries.santricity     1.2.13 
netbox.netbox                 3.1.1  
ngine_io.cloudstack           2.1.0  
ngine_io.exoscale             1.0.0  
ngine_io.vultr                1.1.0  
openstack.cloud               1.5.0  
openvswitch.openvswitch       2.0.0  
ovirt.ovirt                   1.5.3  
purestorage.flasharray        1.8.0  
purestorage.flashblade        1.6.0  
sensu.sensu_go                1.11.1 
servicenow.servicenow         1.0.6  
splunk.es                     1.0.2  
t_systems_mms.icinga_director 1.18.0 
theforeman.foreman            2.1.1  
vyos.vyos                     2.3.1  
wti.remote                    1.0.1  

# /home/m/.ansible/collections/ansible_collections
Collection           Version 
-------------------- --------
amazon.aws           1.5.0   
ansible.netcommon    1.5.0   
community.aws        1.5.0   
community.crypto     1.6.1   
community.dns        2.0.0-a1
community.docker     1.4.0   
community.general    3.0.0   
community.libvirt    1.0.1   
community.proxysql   1.0.1   
devsec.hardening     7.5.0   
google.cloud         1.0.1   
hetzner.hcloud       1.4.4   
lekker.aws           0.0.3   
markuman.hetzner_dns 1.6.1   
markuman.nessus      0.0.4   
markuman.nextcloud   7.0.0   
CONFIGURATION
$ ansible-config dump --only-changed
INTERPRETER_PYTHON(/home/m/git/osuv/ansible.cfg) = /usr/bin/python3
OS / ENVIRONMENT

Linux 5.11.22

STEPS TO REPRODUCE
---
- name: infra
  hosts: localhost
  connection: local
  tags:
    - infra

  tasks:
    - name: Create a firewall 
      hetzner.hcloud.hcloud_firewall:
        name: home
        rules:
          - direction: in
            protocol: icmp
            source_ips:
              - 0.0.0.0/0
              - ::/0
          - direction: in
            protocol: tcp
            source_ips:
              - 0.0.0.0/0
              - ::/0
            port: "80"
          - direction: in
            protocol: tcp
            source_ips:
              - 0.0.0.0/0
              - ::/0
            port: "443"
          - direction: in
            protocol: tcp
            source_ips:
              - 0.0.0.0/0
              - ::/0
            port: "22"
          - direction: in
            protocol: tcp
            source_ips:
              - 0.0.0.0/0
              - ::/0
            port: "61800"
        state: present

    - name: create home.osuv.de
      hetzner.hcloud.hcloud_server:
        name: home.osuv.de
        server_type: cx41
        image: ubuntu-20.04
        location: fsn1
        ssh_keys:
          - m@rocket
        state: present
        rebuild_protection: yes
        delete_protection: yes
        backups: yes
        firewalls:
          - home
      register: HOME

    - name: Create a reverse DNS entry for a server
      hetzner.hcloud.hcloud_server.hcloud_rdns:
        server: home
        ip_address: "{{ HOME.hcloud_server.ipv4_address }}"
        dns_ptr: home.osuv.de
        state: present
EXPECTED RESULTS

rdns value is set without errors

ACTUAL RESULTS
The full traceback is:
Traceback (most recent call last):
  File "/home/m/.ansible/tmp/ansible-tmp-1626895780.912214-1142532-234375814091018/AnsiballZ_hcloud_rdns.py", line 100, in <module>
    _ansiballz_main()
  File "/home/m/.ansible/tmp/ansible-tmp-1626895780.912214-1142532-234375814091018/AnsiballZ_hcloud_rdns.py", line 92, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/m/.ansible/tmp/ansible-tmp-1626895780.912214-1142532-234375814091018/AnsiballZ_hcloud_rdns.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.hetzner.hcloud.plugins.modules.hcloud_rdns', init_globals=dict(_module_fqn='ansible_collections.hetzner.hcloud.plugins.modules.hcloud_rdns', _modlib_path=modlib_path),
  File "/usr/lib/python3.9/runpy.py", line 210, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_hetzner.hcloud.hcloud_server.hcloud_rdns_payload_n46crppb/ansible_hetzner.hcloud.hcloud_server.hcloud_rdns_payload.zip/ansible_collections/hetzner/hcloud/plugins/modules/hcloud_rdns.py", line 280, in <module>
  File "/tmp/ansible_hetzner.hcloud.hcloud_server.hcloud_rdns_payload_n46crppb/ansible_hetzner.hcloud.hcloud_server.hcloud_rdns_payload.zip/ansible_collections/hetzner/hcloud/plugins/modules/hcloud_rdns.py", line 274, in main
  File "/tmp/ansible_hetzner.hcloud.hcloud_server.hcloud_rdns_payload_n46crppb/ansible_hetzner.hcloud.hcloud_server.hcloud_rdns_payload.zip/ansible_collections/hetzner/hcloud/plugins/modules/hcloud_rdns.py", line 228, in present_rdns
  File "/tmp/ansible_hetzner.hcloud.hcloud_server.hcloud_rdns_payload_n46crppb/ansible_hetzner.hcloud.hcloud_server.hcloud_rdns_payload.zip/ansible_collections/hetzner/hcloud/plugins/modules/hcloud_rdns.py", line 157, in _get_rdns
AttributeError: 'NoneType' object has no attribute 'public_net'
fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/m/.ansible/tmp/ansible-tmp-1626895780.912214-1142532-234375814091018/AnsiballZ_hcloud_rdns.py\", line 100, in <module>\n    _ansiballz_main()\n  File \"/home/m/.ansible/tmp/ansible-tmp-1626895780.912214-1142532-234375814091018/AnsiballZ_hcloud_rdns.py\", line 92, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/m/.ansible/tmp/ansible-tmp-1626895780.912214-1142532-234375814091018/AnsiballZ_hcloud_rdns.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.hetzner.hcloud.plugins.modules.hcloud_rdns', init_globals=dict(_module_fqn='ansible_collections.hetzner.hcloud.plugins.modules.hcloud_rdns', _modlib_path=modlib_path),\n  File \"/usr/lib/python3.9/runpy.py\", line 210, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_hetzner.hcloud.hcloud_server.hcloud_rdns_payload_n46crppb/ansible_hetzner.hcloud.hcloud_server.hcloud_rdns_payload.zip/ansible_collections/hetzner/hcloud/plugins/modules/hcloud_rdns.py\", line 280, in <module>\n  File \"/tmp/ansible_hetzner.hcloud.hcloud_server.hcloud_rdns_payload_n46crppb/ansible_hetzner.hcloud.hcloud_server.hcloud_rdns_payload.zip/ansible_collections/hetzner/hcloud/plugins/modules/hcloud_rdns.py\", line 274, in main\n  File \"/tmp/ansible_hetzner.hcloud.hcloud_server.hcloud_rdns_payload_n46crppb/ansible_hetzner.hcloud.hcloud_server.hcloud_rdns_payload.zip/ansible_collections/hetzner/hcloud/plugins/modules/hcloud_rdns.py\", line 228, in present_rdns\n  File \"/tmp/ansible_hetzner.hcloud.hcloud_server.hcloud_rdns_payload_n46crppb/ansible_hetzner.hcloud.hcloud_server.hcloud_rdns_payload.zip/ansible_collections/hetzner/hcloud/plugins/modules/hcloud_rdns.py\", line 157, in _get_rdns\nAttributeError: 'NoneType' object has no attribute 'public_net'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}
LKaemmerling commented 3 years ago

Hey @markuman,

there are several typos in your configuration.

hetzner.hcloud.hcloud_server.hcloud_rdns:

should be

hetzner.hcloud.hcloud_rdns:

And the server name you use in this rdns config does not exist. (You create a server with the name home.osuv.de before but in the rdns you reference only home.

Regardless of this, the error message should be clear yes. We will look into this.

markuman commented 3 years ago

Ah right.

    - name: Create a reverse DNS entry for a server
      hetzner.hcloud.hcloud_rdns:
        server: home.osuv.de
        ip_address: "{{ HOME.hcloud_server.ipv4_address }}"
        dns_ptr: home.osuv.de
        state: present

It was to late. thx!