fix: fix proxmox env var support for inventory plugin and kvm module #4

Merged
xoxys merged 1 commits from proxmox-env into main 2023-01-31 20:35:03 +00:00
2 changed files with 28 additions and 9 deletions
Showing only changes of commit e796104a76 - Show all commits

View File

@ -28,24 +28,33 @@ options:
- Specify the target host of the Proxmox VE cluster. - Specify the target host of the Proxmox VE cluster.
type: str type: str
required: true required: true
env:
- name: PROXMOX_SERVER
api_user: api_user:
description: description:
- Specify the user to authenticate with. - Specify the user to authenticate with.
type: str type: str
required: true required: true
env:
- name: PROXMOX_USER
api_password: api_password:
description: description:
- Specify the password to authenticate with. - Specify the password to authenticate with.
- You can use C(PROXMOX_PASSWORD) environment variable.
type: str type: str
env:
- name: PROXMOX_PASSWORD
api_token_id: api_token_id:
description: description:
- Specify the token ID. - Specify the token ID.
type: str type: str
env:
- name: PROXMOX_TOKEN_ID
api_token_secret: api_token_secret:
description: description:
- Specify the token secret. - Specify the token secret.
type: str type: str
env:
- name: PROXMOX_TOKEN_SECRET
verify_ssl: verify_ssl:
description: description:
- If C(false), SSL certificates will not be validated. - If C(false), SSL certificates will not be validated.
@ -120,7 +129,7 @@ class InventoryModule(BaseInventoryPlugin):
NAME = "xoxys.general.proxmox" NAME = "xoxys.general.proxmox"
def _auth(self): def _proxmox_auth(self):
auth_args = {"user": self.get_option("api_user")} auth_args = {"user": self.get_option("api_user")}
if not (self.get_option("api_token_id") and self.get_option("api_token_secret")): if not (self.get_option("api_token_id") and self.get_option("api_token_secret")):
auth_args["password"] = self.get_option("api_password") auth_args["password"] = self.get_option("api_password")
@ -132,7 +141,7 @@ class InventoryModule(BaseInventoryPlugin):
if not verify_ssl and HAS_URLLIB3: if not verify_ssl and HAS_URLLIB3:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
return ProxmoxAPI( self.client = ProxmoxAPI(
self.get_option("api_host"), self.get_option("api_host"),
verify_ssl=verify_ssl, verify_ssl=verify_ssl,
timeout=self.get_option("auth_timeout"), timeout=self.get_option("auth_timeout"),
@ -307,5 +316,5 @@ class InventoryModule(BaseInventoryPlugin):
super().parse(inventory, loader, path) super().parse(inventory, loader, path)
self._read_config_data(path) self._read_config_data(path)
self.client = self._auth() self._proxmox_auth()
self._propagate() self._propagate()

View File

@ -36,11 +36,13 @@ options:
api_host: api_host:
description: description:
- Specify the target host of the Proxmox VE cluster. - Specify the target host of the Proxmox VE cluster.
- You can use C(PROXMOX_SERVER) environment variable.
type: str type: str
required: true required: true
api_user: api_user:
description: description:
- Specify the user to authenticate with. - Specify the user to authenticate with.
- You can use C(PROXMOX_USER) environment variable.
type: str type: str
required: true required: true
api_password: api_password:
@ -51,11 +53,13 @@ options:
api_token_id: api_token_id:
description: description:
- Specify the token ID. - Specify the token ID.
- You can use C(PROXMOX_TOKEN_ID) environment variable.
type: str type: str
version_added: 1.3.0 version_added: 1.3.0
api_token_secret: api_token_secret:
description: description:
- Specify the token secret. - Specify the token secret.
- You can use C(PROXMOX_TOKEN_SECRET) environment variable.
type: str type: str
version_added: 1.3.0 version_added: 1.3.0
verify_ssl: verify_ssl:
@ -1076,11 +1080,17 @@ def main():
acpi=dict(type="bool"), acpi=dict(type="bool"),
agent=dict(type="bool"), agent=dict(type="bool"),
args=dict(type="str"), args=dict(type="str"),
api_host=dict(required=True, type="str"), api_host=dict(required=True, type="str", fallback=(env_fallback, ["PROXMOX_SERVER"])),
api_password=dict(no_log=True, fallback=(env_fallback, ["PROXMOX_PASSWORD"])), api_user=dict(required=True, type="str", fallback=(env_fallback, ["PROXMOX_USER"])),
api_token_id=dict(no_log=True), api_password=dict(
api_token_secret=dict(no_log=True), no_log=True, type="str", fallback=(env_fallback, ["PROXMOX_PASSWORD"])
api_user=dict(required=True), ),
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"), autostart=dict(type="bool"),
balloon=dict(type="int"), balloon=dict(type="int"),
bios=dict(choices=["seabios", "ovmf"]), bios=dict(choices=["seabios", "ovmf"]),