1
- name: Vault Test 
  set_fact:
    msg: "{{ lookup('hashi_vault', 'secret=secret token=token url=https://address')}}"

I hava a error when run this palybook:

fatal: [*****]: FAILED! => {"msg": "An unhandled exception occurred while running the lookup plugin 'hashi_vault'. Error was a <class 'ansible.errors.AnsibleError'>, original message: Please pip install hvac to use the hashi_vault lookup module.. Please pip install hvac to use the hashi_vault lookup module."}

but I have installed the havc

ansible            5.9.0
ansible-core       2.12.7
hvac               0.10.8
pyhcl              0.4.4
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
mario xu
  • 11
  • 1
  • 2

2 Answers2

0

I had the same problem. There is an issue closed in the ansible github about this: hashi_vault not recognizing hvac

Quoting:

depends on what Python install Ansible is using. Running:

ansible -m debug -a 'var=ansible_playbook_python' localhost

will show you what Ansible is using to run lookups.

pip install hvac on that Python, and your problem will resolve.

In my case, it returned the python for the local python env I was using.

I went the extra mile, modified the HVAC source code, and got a different interpreter being used by the local plugin (redacted)

/home/.../project_root/env/bin/ansible-playbook            

and it worked.

Wakaru44
  • 423
  • 4
  • 14
0

let me add 2 cents.

as described above first you need to find the version of python is used via

   $ ansible -m debug -a 'var=ansible_playbook_python' localhost

if it is python2 then use

$ pip  install hvac[parser]

if it is python3 then use

$ pip3  install hvac[parser]
Alex
  • 837
  • 8
  • 9