jhaals / ansible-vault

ansible lookup plugin for secrets stored in Vault(by HashiCorp)
BSD 3-Clause "New" or "Revised" License
347 stars 65 forks source link

Environment variables #8

Closed lukasmrtvy closed 7 years ago

lukasmrtvy commented 8 years ago

Is possible to use environment variables in ansible playbook? Just like my example? Because i cant get it work...

- hosts: localhost
  vars:
    vault1_env:
      VAULT_ADDR: https://localhost:8200/
      VAULT_TOKEN: my-token-id
      VAULT_SKIP_VERIFY: True

  tasks:
     - debug: msg="{{ lookup('vault', 'secret/hello', 'value') }}"
     - shell: echo VAULT_ADDR is $VAULT_ADDR, VAULT_TOKEN is $VAULT_TOKEN, VAULT_SKIP_VERIFY is $VAULT_SKIP_VERIFY
       environment: "{{ vault1_env }}"
       register: shellout
     - debug: var=shellout
justinlarose commented 8 years ago

If you figure this out, please reply back to the thread. I'm actually trying to do this as well.

sidick commented 8 years ago

Correcting my previous comment, surely you need to use environment: in the first debug command too?

Edit: hmm, see what you mean, complains about in VAULT_ADDR variable here too

richfromm commented 7 years ago

The issue is that when you're setting environment variables like this, you are setting them on the remote host. The environment variables that control Vault need to be set on the deploy (local) host.

As of #27, you can now set vault_addr, vault_cacert, and vault_capath as Ansible variables.

Note that vault_token is explicitly left out of that list. However, as of #25 you can now set that via the file ~/.vault_token

jhaals commented 7 years ago

I consider this to be fixed thanks to @richfromm