ansible-collections / community.hashi_vault

Ansible collection for managing and working with HashiCorp Vault.
https://docs.ansible.com/ansible/devel/collections/community/hashi_vault/index.html
GNU General Public License v3.0
80 stars 59 forks source link

Add ability to use ansible vars to specify options #86

Closed briantist closed 3 years ago

briantist commented 3 years ago
SUMMARY

Fixes #49 Fixes #65

The big change here is adding vars: entries for several options:

Some new examples of usage:

- name: use ansible vars to supply some options
  vars:
    ansible_hashi_vault_url: 'https://myvault:8282'
    ansible_hashi_vault_auth_method: token
  set_fact:
    secret1: "{{ lookup('secret/data/secret1') }}"
    secret2: "{{ lookup('secret/data/secret2') }}"

- name: use proxies with a dict (as direct ansible var)
  vars:
    ansible_hashi_vault_proxies:
      http: http://myproxy1
      https: https://myproxy2
  ansible.builtin.debug:
    msg: "{{ lookup('community.hashi_vault.hashi_vault', '...' }}"

Important Note

Using templating in task vars won't work because of https://github.com/ansible/ansible/issues/73268 so this example will fail:

- name: use ansible vars to supply some options
  vars:
    ansible_hashi_vault_url: '{{ my_other_url }}'
  debug:
    msg: "{{ lookup('secret/data/secret1') }}"

Instead, use set_fact to ensure your vars are evaluated beforehand.

- set_fact:
    ansible_hashi_vault_url: '{{ my_other_url }}'

- name: use ansible vars to supply some options
  debug:
    msg: "{{ lookup('secret/data/secret1') }}"

Other Changes

ISSUE TYPE
COMPONENT NAME

hashi_vault

ADDITIONAL INFORMATION
codecov[bot] commented 3 years ago

Codecov Report

Merging #86 (c3fea8d) into main (a6e6f37) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #86   +/-   ##
=======================================
  Coverage   82.88%   82.88%           
=======================================
  Files          16       16           
  Lines         783      783           
  Branches       78       78           
=======================================
  Hits          649      649           
  Misses        120      120           
  Partials       14       14           
Impacted Files Coverage Δ
plugins/doc_fragments/connection.py 100.00% <ø> (ø)
plugins/lookup/hashi_vault.py 63.15% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update a6e6f37...c3fea8d. Read the comment docs.

briantist commented 3 years ago

cc @h3m5k @erinn @morco @elcomtik @pilou- @wenottingham @infra-monkey

Would you be able to try out this PR with AWX and see if it meets your needs for supplying values that don't rely on environment variables?

grnrk commented 3 years ago

I'v tested this with AWX 15.0.1 and ansible 2.10.6 and it works like a charm. The vars included in the test were (on separate occasions): ansible_hashi_vault_url ansible_hashi_vault_addr ansible_hashi_vault_token ansible_hashi_vault_role_id ansible_hashi_vault_secret_id ansible_hashi_vault_auth_method

Let me know if you'd like me to try something else. Thanks a bunch!

briantist commented 3 years ago

@h3m5k great! thanks a lot, I really appreciate that extra testing. Given how important it is to AWX users I wanted someone to use it hands-on before merging in case anything else was needed.