diff --git a/lib/ansible/plugins/lookup/hashi_vault.py b/lib/ansible/plugins/lookup/hashi_vault.py index 4d9bb4f6c38..d92bf149119 100644 --- a/lib/ansible/plugins/lookup/hashi_vault.py +++ b/lib/ansible/plugins/lookup/hashi_vault.py @@ -54,7 +54,16 @@ class HashiVault: raise AnsibleError("Please pip install hvac to use this module") self.url = kwargs.get('url', ANSIBLE_HASHI_VAULT_ADDR) - self.token = kwargs.get('token') + + self.token = kwargs.get('token', os.environ.get('VAULT_TOKEN', None)) + if self.token is None and os.environ.get('HOME'): + token_filename = os.path.join( + os.environ.get('HOME'), + '.vault-token' + ) + if os.path.exists(token_filename): + with open(token_filename) as token_file: + self.token = token_file.read().strip() if self.token is None: raise AnsibleError("No Vault Token specified")