mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* added templating to the url, user, and password
* added changelog fragment
* typo in description for url, and password
* clarify in the changelog what can you change
* update documentation and added an example
* missing quote from examples
* Apply suggestions from code review
Changed to I for option names
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update plugins/inventory/proxmox.py
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 13d18c9aa8
)
Co-authored-by: Ilija Matoski <ilijamt@gmail.com>
This commit is contained in:
parent
868edfa664
commit
3376442aa2
2 changed files with 33 additions and 3 deletions
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
minor_changes:
|
||||||
|
- proxmox inventory plugin - add support for templating the ``url``, ``user``, and ``password`` options
|
||||||
|
(https://github.com/ansible-collections/community.general/pull/4418).
|
|
@ -31,6 +31,7 @@ DOCUMENTATION = '''
|
||||||
description:
|
description:
|
||||||
- URL to Proxmox cluster.
|
- URL to Proxmox cluster.
|
||||||
- If the value is not specified in the inventory configuration, the value of environment variable C(PROXMOX_URL) will be used instead.
|
- If the value is not specified in the inventory configuration, the value of environment variable C(PROXMOX_URL) will be used instead.
|
||||||
|
- Since community.general 4.7.0 you can also use templating to specify the value of the I(url).
|
||||||
default: 'http://localhost:8006'
|
default: 'http://localhost:8006'
|
||||||
type: str
|
type: str
|
||||||
env:
|
env:
|
||||||
|
@ -40,6 +41,7 @@ DOCUMENTATION = '''
|
||||||
description:
|
description:
|
||||||
- Proxmox authentication user.
|
- Proxmox authentication user.
|
||||||
- If the value is not specified in the inventory configuration, the value of environment variable C(PROXMOX_USER) will be used instead.
|
- If the value is not specified in the inventory configuration, the value of environment variable C(PROXMOX_USER) will be used instead.
|
||||||
|
- Since community.general 4.7.0 you can also use templating to specify the value of the I(user).
|
||||||
required: yes
|
required: yes
|
||||||
type: str
|
type: str
|
||||||
env:
|
env:
|
||||||
|
@ -49,6 +51,7 @@ DOCUMENTATION = '''
|
||||||
description:
|
description:
|
||||||
- Proxmox authentication password.
|
- Proxmox authentication password.
|
||||||
- If the value is not specified in the inventory configuration, the value of environment variable C(PROXMOX_PASSWORD) will be used instead.
|
- If the value is not specified in the inventory configuration, the value of environment variable C(PROXMOX_PASSWORD) will be used instead.
|
||||||
|
- Since community.general 4.7.0 you can also use templating to specify the value of the I(password).
|
||||||
required: yes
|
required: yes
|
||||||
type: str
|
type: str
|
||||||
env:
|
env:
|
||||||
|
@ -136,6 +139,14 @@ compose:
|
||||||
my_inv_var_1: "'my_var1_value'"
|
my_inv_var_1: "'my_var1_value'"
|
||||||
my_inv_var_2: >
|
my_inv_var_2: >
|
||||||
"my_var_2_value"
|
"my_var_2_value"
|
||||||
|
|
||||||
|
# Specify the url, user and password using templating
|
||||||
|
# my.proxmox.yml
|
||||||
|
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) }}"
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
|
@ -148,6 +159,7 @@ from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cachea
|
||||||
from ansible.module_utils.common.text.converters import to_native
|
from ansible.module_utils.common.text.converters import to_native
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
||||||
from ansible.utils.display import Display
|
from ansible.utils.display import Display
|
||||||
|
from ansible.template import Templar
|
||||||
|
|
||||||
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
|
||||||
|
|
||||||
|
@ -500,10 +512,24 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||||
# read config from file, this sets 'options'
|
# read config from file, this sets 'options'
|
||||||
self._read_config_data(path)
|
self._read_config_data(path)
|
||||||
|
|
||||||
|
t = Templar(loader=loader)
|
||||||
|
|
||||||
# read options
|
# read options
|
||||||
self.proxmox_url = self.get_option('url').rstrip('/')
|
proxmox_url = self.get_option('url')
|
||||||
self.proxmox_user = self.get_option('user')
|
if t.is_template(proxmox_url):
|
||||||
self.proxmox_password = self.get_option('password')
|
proxmox_url = t.template(variable=proxmox_url, disable_lookups=False)
|
||||||
|
self.proxmox_url = proxmox_url.rstrip('/')
|
||||||
|
|
||||||
|
proxmox_user = self.get_option('user')
|
||||||
|
if t.is_template(proxmox_user):
|
||||||
|
proxmox_user = t.template(variable=proxmox_user, disable_lookups=False)
|
||||||
|
self.proxmox_user = proxmox_user
|
||||||
|
|
||||||
|
proxmox_password = self.get_option('password')
|
||||||
|
if t.is_template(proxmox_password):
|
||||||
|
proxmox_password = t.template(variable=proxmox_password, disable_lookups=False)
|
||||||
|
self.proxmox_password = proxmox_password
|
||||||
|
|
||||||
self.cache_key = self.get_cache_key(path)
|
self.cache_key = self.get_cache_key(path)
|
||||||
self.use_cache = cache and self.get_option('cache')
|
self.use_cache = cache and self.get_option('cache')
|
||||||
self.host_filters = self.get_option('filters')
|
self.host_filters = self.get_option('filters')
|
||||||
|
|
Loading…
Reference in a new issue