fix: fix proxmox env var support for inventory plugin and kvm module (#4)
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Robert Kaussow 2023-01-31 21:35:03 +01:00
parent dcf04af784
commit f8edc9269f
2 changed files with 28 additions and 9 deletions

View File

@ -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()

View File

@ -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"]),