From f8edc9269f55bd6dd9b2356a8581cde2a223d8cd Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Tue, 31 Jan 2023 21:35:03 +0100 Subject: [PATCH] fix: fix proxmox env var support for inventory plugin and kvm module (#4) --- plugins/inventory/proxmox.py | 17 +++++++++++++---- plugins/modules/proxmox_kvm.py | 20 +++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index fcd2b71..555ab45 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -28,24 +28,33 @@ options: - Specify the target host of the Proxmox VE cluster. type: str required: true + env: + - name: PROXMOX_SERVER api_user: description: - Specify the user to authenticate with. type: str required: true + env: + - name: PROXMOX_USER api_password: description: - Specify the password to authenticate with. - - You can use C(PROXMOX_PASSWORD) environment variable. type: str + env: + - name: PROXMOX_PASSWORD api_token_id: description: - Specify the token ID. type: str + env: + - name: PROXMOX_TOKEN_ID api_token_secret: description: - Specify the token secret. type: str + env: + - name: PROXMOX_TOKEN_SECRET verify_ssl: description: - If C(false), SSL certificates will not be validated. @@ -120,7 +129,7 @@ class InventoryModule(BaseInventoryPlugin): NAME = "xoxys.general.proxmox" - def _auth(self): + def _proxmox_auth(self): auth_args = {"user": self.get_option("api_user")} if not (self.get_option("api_token_id") and self.get_option("api_token_secret")): auth_args["password"] = self.get_option("api_password") @@ -132,7 +141,7 @@ class InventoryModule(BaseInventoryPlugin): if not verify_ssl and HAS_URLLIB3: urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) - return ProxmoxAPI( + self.client = ProxmoxAPI( self.get_option("api_host"), verify_ssl=verify_ssl, timeout=self.get_option("auth_timeout"), @@ -307,5 +316,5 @@ class InventoryModule(BaseInventoryPlugin): super().parse(inventory, loader, path) self._read_config_data(path) - self.client = self._auth() + self._proxmox_auth() self._propagate() diff --git a/plugins/modules/proxmox_kvm.py b/plugins/modules/proxmox_kvm.py index e7cb082..268e21c 100644 --- a/plugins/modules/proxmox_kvm.py +++ b/plugins/modules/proxmox_kvm.py @@ -36,11 +36,13 @@ options: api_host: description: - Specify the target host of the Proxmox VE cluster. + - You can use C(PROXMOX_SERVER) environment variable. type: str required: true api_user: description: - Specify the user to authenticate with. + - You can use C(PROXMOX_USER) environment variable. type: str required: true api_password: @@ -51,11 +53,13 @@ options: api_token_id: description: - Specify the token ID. + - You can use C(PROXMOX_TOKEN_ID) environment variable. type: str version_added: 1.3.0 api_token_secret: description: - Specify the token secret. + - You can use C(PROXMOX_TOKEN_SECRET) environment variable. type: str version_added: 1.3.0 verify_ssl: @@ -1076,11 +1080,17 @@ def main(): acpi=dict(type="bool"), agent=dict(type="bool"), args=dict(type="str"), - api_host=dict(required=True, type="str"), - api_password=dict(no_log=True, fallback=(env_fallback, ["PROXMOX_PASSWORD"])), - api_token_id=dict(no_log=True), - api_token_secret=dict(no_log=True), - api_user=dict(required=True), + api_host=dict(required=True, type="str", fallback=(env_fallback, ["PROXMOX_SERVER"])), + api_user=dict(required=True, type="str", fallback=(env_fallback, ["PROXMOX_USER"])), + api_password=dict( + no_log=True, type="str", fallback=(env_fallback, ["PROXMOX_PASSWORD"]) + ), + api_token_id=dict( + no_log=True, type="str", fallback=(env_fallback, ["PROXMOX_TOKEN_ID"]) + ), + api_token_secret=dict( + no_log=True, type="str", fallback=(env_fallback, ["PROXMOX_TOKEN_SECRET"]) + ), autostart=dict(type="bool"), balloon=dict(type="int"), bios=dict(choices=["seabios", "ovmf"]),