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
This commit is contained in:
parent
857a9ce526
commit
29e37e9641
1 changed files with 11 additions and 5 deletions
|
|
@ -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: The Hetzner Cloud API Token.
|
||||
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 environemt variable set by token_env option."
|
||||
)
|
||||
|
||||
self.endpoint = os.getenv("HCLOUD_ENDPOINT") or "https://api.hetzner.cloud/v1"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue