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

2.4.0 breaks `refresh_inventory` #403

Closed fabrykowski closed 10 months ago

fabrykowski commented 10 months ago
SUMMARY

The new version 2.4.0 breaks the functionality of ansible.builtin.meta: refresh_inventory, when using the provided dynamic inventory hetzner.hcloud.hcloud.

ISSUE TYPE
COMPONENT NAME

hetzner.hcloud.hcloud

ANSIBLE VERSION
ansible-playbook [core 2.16.0]
  config file = /Users/test/hcloud-mre/ansible.cfg
  configured module search path = ['/Users/test/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/Cellar/ansible/9.0.1/libexec/lib/python3.12/site-packages/ansible
  ansible collection location = /Users/test/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible-playbook
  python version = 3.12.0 (main, Oct  2 2023, 12:03:24) [Clang 15.0.0 (clang-1500.0.40.1)] (/opt/homebrew/Cellar/ansible/9.0.1/libexec/bin/python)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
ansible-galaxy [core 2.16.0]
  config file = /Users/test/hcloud-mre/ansible.cfg
  configured module search path = ['/Users/test/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/Cellar/ansible/9.0.1/libexec/lib/python3.12/site-packages/ansible
  ansible collection location = /Users/test/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible-galaxy
  python version = 3.12.0 (main, Oct  2 2023, 12:03:24) [Clang 15.0.0 (clang-1500.0.40.1)] (/opt/homebrew/Cellar/ansible/9.0.1/libexec/bin/python)
  jinja version = 3.1.2
  libyaml = True
Using /Users/test/hcloud-mre/ansible.cfg as config file

# /Users/test/.ansible/collections/ansible_collections
Collection     Version
-------------- -------
hetzner.hcloud 2.4.0  

# /opt/homebrew/Cellar/ansible/9.0.1/libexec/lib/python3.12/site-packages/ansible_collections
Collection     Version
-------------- -------
hetzner.hcloud 2.3.0  
CONFIGURATION
ansible-config [core 2.16.0]
  config file = /Users/test/hcloud-mre/ansible.cfg
  configured module search path = ['/Users/test/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/Cellar/ansible/9.0.1/libexec/lib/python3.12/site-packages/ansible
  ansible collection location = /Users/test/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible-config
  python version = 3.12.0 (main, Oct  2 2023, 12:03:24) [Clang 15.0.0 (clang-1500.0.40.1)] (/opt/homebrew/Cellar/ansible/9.0.1/libexec/bin/python)
  jinja version = 3.1.2
  libyaml = True
Using /Users/test/hcloud-mre/ansible.cfg as config file
CONFIG_FILE() = /Users/test/hcloud-mre/ansible.cfg
DEFAULT_HOST_LIST(/Users/test/hcloud-mre/ansible.cfg) = ['/Users/test/hcloud-mre/inventory.hcloud.yml']
DEFAULT_VERBOSITY(env: ANSIBLE_VERBOSITY) = 2
HOST_KEY_CHECKING(/Users/test/hcloud-mre/ansible.cfg) = False
INVENTORY_ENABLED(/Users/test/hcloud-mre/ansible.cfg) = ['hetzner.hcloud.hcloud']
PAGER(env: PAGER) = less
OS / ENVIRONMENT

macOS Sonoma 14.1.1

STEPS TO REPRODUCE

Environment variables:

inventory.hcloud.yml:

plugin: hetzner.hcloud.hcloud
keyed_groups:
  - key: labels
    trailing_separator: false
leading_separator: false

playbook.yml:

- hosts: localhost
  tasks:
    - debug:
        msg: "hcloud version {{ lookup('community.general.collection_version', 'hetzner.hcloud') }}"
    - debug:
        var: hostvars
    - hetzner.hcloud.hcloud_server:
        name: test
        server_type: cx11
        image: debian-12
        location: nbg1
        ssh_keys:
          - test
    - meta: refresh_inventory
    - debug:
        var: hostvars
EXPECTED RESULTS

This is the output for version 2.3.0:

ansible-playbook [core 2.16.0]
  config file = /Users/test/hcloud-mre/ansible.cfg
  configured module search path = ['/Users/test/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/Cellar/ansible/9.0.1/libexec/lib/python3.12/site-packages/ansible
  ansible collection location = /Users/test/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible-playbook
  python version = 3.12.0 (main, Oct  2 2023, 12:03:24) [Clang 15.0.0 (clang-1500.0.40.1)] (/opt/homebrew/Cellar/ansible/9.0.1/libexec/bin/python)
  jinja version = 3.1.2
  libyaml = True
Using /Users/test/hcloud-mre/ansible.cfg as config file
[WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match 'all'
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: playbook.yml *********************************************************
1 plays in test/playbook.yml

PLAY [localhost] ***************************************************************

TASK [debug] *******************************************************************
task path: /Users/test/hcloud-mre/playbook.yml:3
ok: [localhost] => {
    "msg": "hcloud version 2.3.0"
}

TASK [debug] *******************************************************************
task path: /Users/test/hcloud-mre/playbook.yml:5
ok: [localhost] => {
    "hostvars": {}
}

TASK [hetzner.hcloud.hcloud_server] ********************************************
task path: /Users/test/hcloud-mre/playbook.yml:7
changed: [localhost] => {"changed": true, "hcloud_server": {"backup_window": null, "created": "2023-11-24T17:41:32+00:00", "datacenter": "nbg1-dc3", "delete_protection": false, "id": "39777052", "image": "debian-12", "ipv4_address": "159.69.156.71", "ipv6": "2a01:4f8:1c1c:3dec::/64", "labels": {}, "location": "nbg1", "name": "test", "placement_group": null, "private_networks": [], "private_networks_info": [], "rebuild_protection": false, "rescue_enabled": false, "server_type": "cx11", "status": "running"}, "root_password": null}

TASK [meta] ********************************************************************
task path: /Users/test/hcloud-mre/playbook.yml:14
META: inventory successfully refreshed

TASK [debug] *******************************************************************
task path: /Users/test/hcloud-mre/playbook.yml:15
ok: [localhost] => {
    "hostvars": {
        "test": {
            "ansible_check_mode": false,
            "ansible_config_file": "/Users/test/hcloud-mre/ansible.cfg",
            "ansible_diff_mode": false,
            "ansible_facts": {},
            "ansible_forks": 5,
            "ansible_host": "159.69.156.71",
            "ansible_inventory_sources": [
                "/Users/test/hcloud-mre/inventory.hcloud.yml"
            ],
            "ansible_playbook_python": "/opt/homebrew/Cellar/ansible/9.0.1/libexec/bin/python",
            "ansible_run_tags": [
                "all"
            ],
            "ansible_skip_tags": [],
            "ansible_verbosity": 2,
            "ansible_version": {
                "full": "2.16.0",
                "major": 2,
                "minor": 16,
                "revision": 0,
                "string": "2.16.0"
            },
            "architecture": "x86",
            "datacenter": "nbg1-dc3",
            "group_names": [
                "hcloud"
            ],
            "groups": {
                "all": [
                    "test"
                ],
                "hcloud": [
                    "test"
                ],
                "ungrouped": []
            },
            "id": 39777052,
            "image_id": 114690387,
            "image_name": "debian-12",
            "image_os_flavor": "debian",
            "inventory_dir": "/Users/test/hcloud-mre",
            "inventory_file": "/Users/test/hcloud-mre/inventory.hcloud.yml",
            "inventory_hostname": "test",
            "inventory_hostname_short": "test",
            "ipv4": "159.69.156.71",
            "ipv6": "2a01:4f8:1c1c:3dec::1",
            "ipv6_network": "2a01:4f8:1c1c:3dec::",
            "ipv6_network_mask": "64",
            "labels": {},
            "location": "nbg1",
            "name": "test",
            "omit": "__omit_place_holder__13e40a042d06f244cd8b319d6a477a2fc0200494",
            "playbook_dir": "/Users/test/hcloud-mre",
            "private_networks": [],
            "server_type": "cx11",
            "status": "running",
            "type": "cx11"
        }
    }
}

PLAY RECAP *********************************************************************
localhost                  : ok=4    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

After the server has been created and the inventory refreshed, the variable hostvars contains the server's information.

ACTUAL RESULTS

This is the output for version 2.4.0:

ansible-playbook [core 2.16.0]
  config file = /Users/test/hcloud-mre/ansible.cfg
  configured module search path = ['/Users/test/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/Cellar/ansible/9.0.1/libexec/lib/python3.12/site-packages/ansible
  ansible collection location = /Users/test/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible-playbook
  python version = 3.12.0 (main, Oct  2 2023, 12:03:24) [Clang 15.0.0 (clang-1500.0.40.1)] (/opt/homebrew/Cellar/ansible/9.0.1/libexec/bin/python)
  jinja version = 3.1.2
  libyaml = True
Using /Users/test/hcloud-mre/ansible.cfg as config file
[WARNING]: provided hosts list is empty, only localhost is available. Note that
the implicit localhost does not match 'all'
redirecting (type: modules) hetzner.hcloud.hcloud_server to hetzner.hcloud.server
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: playbook.yml *********************************************************
1 plays in test/playbook.yml

PLAY [localhost] ***************************************************************

TASK [debug] *******************************************************************
task path: /Users/test/hcloud-mre/playbook.yml:3
ok: [localhost] => {
    "msg": "hcloud version 2.4.0"
}

TASK [debug] *******************************************************************
task path: /Users/test/hcloud-mre/playbook.yml:5
ok: [localhost] => {
    "hostvars": {}
}

TASK [hetzner.hcloud.hcloud_server] ********************************************
task path: /Users/test/hcloud-mre/playbook.yml:7
redirecting (type: modules) hetzner.hcloud.hcloud_server to hetzner.hcloud.server
redirecting (type: modules) hetzner.hcloud.hcloud_server to hetzner.hcloud.server
changed: [localhost] => {"changed": true, "hcloud_server": {"backup_window": null, "created": "2023-11-24T17:37:31+00:00", "datacenter": "nbg1-dc3", "delete_protection": false, "id": "39776929", "image": "debian-12", "ipv4_address": "159.69.156.71", "ipv6": "2a01:4f8:1c1c:3dec::/64", "labels": {}, "location": "nbg1", "name": "test", "placement_group": null, "private_networks": [], "private_networks_info": [], "rebuild_protection": false, "rescue_enabled": false, "server_type": "cx11", "status": "running"}, "root_password": null}

TASK [meta] ********************************************************************
task path: /Users/test/hcloud-mre/playbook.yml:14
META: inventory successfully refreshed

TASK [debug] *******************************************************************
task path: /Users/test/hcloud-mre/playbook.yml:15
ok: [localhost] => {
    "hostvars": {}
}

PLAY RECAP *********************************************************************
localhost                  : ok=4    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

The variable hostvars remains empty, despite the log claiming "inventory successfully refreshed".