From 865d7ac698e58cf5daa83f2b02f4e873535be6a3 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 10 Apr 2022 08:46:49 +0200 Subject: [PATCH] Deprecate want_proxmox_nodes_ansible_host option's default value. (#4466) --- .../4466-proxmox-ansible_host-deprecation.yml | 6 +++++ plugins/inventory/proxmox.py | 26 +++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/4466-proxmox-ansible_host-deprecation.yml diff --git a/changelogs/fragments/4466-proxmox-ansible_host-deprecation.yml b/changelogs/fragments/4466-proxmox-ansible_host-deprecation.yml new file mode 100644 index 0000000000..a4c94a318c --- /dev/null +++ b/changelogs/fragments/4466-proxmox-ansible_host-deprecation.yml @@ -0,0 +1,6 @@ +deprecated_features: + - "proxmox inventory plugin - the current default ``true`` of the ``want_proxmox_nodes_ansible_host`` option has been deprecated. + The default will change to ``false`` in community.general 6.0.0. To keep the current behavior, explicitly set + ``want_proxmox_nodes_ansible_host`` to ``true`` in your inventory configuration. We suggest to already switch to the new + behavior by explicitly setting it to ``false``, and by using ``compose:`` to set ``ansible_host`` to the correct value. + See the examples in the plugin documentation for details (https://github.com/ansible-collections/community.general/pull/4466)." diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index 6a2186d2c8..7670841666 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -78,7 +78,9 @@ DOCUMENTATION = ''' description: - Whether to set C(ansbile_host) for proxmox nodes. - When set to C(true) (default), will use the first available interface. This can be different from what you expect. - default: true + - This currently defaults to C(true), but the default is deprecated since community.general 4.8.0. + The default will change to C(false) in community.general 6.0.0. To avoid a deprecation warning, please + set this parameter explicitly. type: bool filters: version_added: 4.6.0 @@ -103,6 +105,9 @@ EXAMPLES = ''' plugin: community.general.proxmox user: ansible@pve password: secure +# Note that this can easily give you wrong values as ansible_host. See further below for +# an example where this is set to `false` and where ansible_host is set with `compose`. +want_proxmox_nodes_ansible_host: true # More complete example demonstrating the use of 'want_facts' and the constructed options # Note that using facts returned by 'want_facts' in constructed options requires 'want_facts=true' @@ -123,6 +128,9 @@ groups: mailservers: "'mail' in (proxmox_tags_parsed|list)" compose: ansible_port: 2222 +# Note that this can easily give you wrong values as ansible_host. See further below for +# an example where this is set to `false` and where ansible_host is set with `compose`. +want_proxmox_nodes_ansible_host: true # Using the inventory to allow ansible to connect via the first IP address of the VM / Container # (Default is connection by name of QEMU/LXC guests) @@ -134,6 +142,7 @@ user: ansible@pve password: secure validate_certs: false want_facts: true +want_proxmox_nodes_ansible_host: false compose: ansible_host: proxmox_ipconfig0.ip | default(proxmox_net0.ip) | ipaddr('address') my_inv_var_1: "'my_var1_value'" @@ -146,6 +155,9 @@ plugin: community.general.proxmox url: "{{ lookup('ansible.builtin.ini', 'url', section='proxmox', file='file.ini') }}" user: "{{ lookup('ansible.builtin.env','PM_USER') | default('ansible@pve') }}" password: "{{ lookup('community.general.random_string', base64=True) }}" +# Note that this can easily give you wrong values as ansible_host. See further up for +# an example where this is set to `false` and where ansible_host is set with `compose`. +want_proxmox_nodes_ansible_host: true ''' @@ -467,6 +479,16 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): nodes_group = self._group('nodes') self.inventory.add_group(nodes_group) + want_proxmox_nodes_ansible_host = self.get_option("want_proxmox_nodes_ansible_host") + if want_proxmox_nodes_ansible_host is None: + display.deprecated( + 'The want_proxmox_nodes_ansible_host option of the community.general.proxmox inventory plugin' + ' currently defaults to `true`, but this default has been deprecated and will change to `false`' + ' in community.general 6.0.0. To keep the current behavior and remove this deprecation warning,' + ' explicitly set `want_proxmox_nodes_ansible_host` to `true` in your inventory configuration', + version='6.0.0', collection_name='community.general') + want_proxmox_nodes_ansible_host = True + # gather vm's on nodes self._get_auth() hosts = [] @@ -482,7 +504,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): continue # get node IP address - if self.get_option("want_proxmox_nodes_ansible_host"): + if want_proxmox_nodes_ansible_host: ip = self._get_node_ip(node['node']) self.inventory.set_variable(node['node'], 'ansible_host', ip)