Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inventory plugin: Allow token to be provided through extra-vars. #156

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions plugins/inventory/hcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@
# Minimal example. `HCLOUD_TOKEN` is exposed in environment.
plugin: hcloud

# Example with templated token, e.g. provided through extra vars.
plugin: hcloud
token: "{{ hetzner_apitoken }}"

# Example with locations, types, status and token
plugin: hcloud
token: foobar
Expand Down Expand Up @@ -129,6 +133,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):

def _configure_hcloud_client(self):
self.token_env = self.get_option("token_env")
self.templar.available_variables = self._vars
self.api_token = self.templar.template(self.get_option("token"), fail_on_undefined=False) or os.getenv(self.token_env)
if self.api_token is None:
raise AnsibleError(
Expand Down