1
0
Fork 0
mirror of https://github.com/ansible-collections/hetzner.hcloud.git synced 2026-02-04 08:01:49 +00:00

add token_env option to load token from custom env variable (#43)

Co-authored-by: Lukas Kämmerling <github@lukas-kaemmerling.de>
This commit is contained in:
Robert Kaussow 2020-12-01 08:39:08 +01:00 committed by GitHub
parent 857a9ce526
commit 0d8a8bf7f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,9 +26,12 @@ DOCUMENTATION = r'''
choices: ["hcloud"]
token:
description: The Hetzner Cloud API Token.
required: true
env:
- name: HCLOUD_TOKEN
required: false
token_env:
description: Environment variable to load the Hetzner Cloud API Token from.
default: HCLOUD_TOKEN
type: str
required: false
connect_with:
description: Connect to the server using the value from this field.
default: public_ipv4
@ -107,10 +110,13 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
NAME = 'hetzner.hcloud.hcloud'
def _configure_hcloud_client(self):
self.api_token = self.get_option("token")
self.token_env = self.get_option("token_env")
self.api_token = self.get_option("token") or os.getenv(self.token_env)
if self.api_token is None:
raise AnsibleError(
"Please specify a token, via the option token or via environment variable HCLOUD_TOKEN")
"Please specify a token, via the option token, via environment variable HCLOUD_TOKEN "
"or via custom environment variable set by token_env option."
)
self.endpoint = os.getenv("HCLOUD_ENDPOINT") or "https://api.hetzner.cloud/v1"