{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/15495","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/15495/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/15495/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/15495/events","html_url":"https://github.com/ansible/ansible/issues/15495","id":149734049,"number":15495,"title":"hashi_vault lookup plugin fails with:  KeyError: 'value'","user":{"login":"techraf","id":1206173,"avatar_url":"https://avatars.githubusercontent.com/u/1206173?v=3","gravatar_id":"","url":"https://api.github.com/users/techraf","html_url":"https://github.com/techraf","followers_url":"https://api.github.com/users/techraf/followers","following_url":"https://api.github.com/users/techraf/following{/other_user}","gists_url":"https://api.github.com/users/techraf/gists{/gist_id}","starred_url":"https://api.github.com/users/techraf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/techraf/subscriptions","organizations_url":"https://api.github.com/users/techraf/orgs","repos_url":"https://api.github.com/users/techraf/repos","events_url":"https://api.github.com/users/techraf/events{/privacy}","received_events_url":"https://api.github.com/users/techraf/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ansible/ansible/labels/bug_report","name":"bug_report","color":"fbca04"},{"url":"https://api.github.com/repos/ansible/ansible/labels/needs_info","name":"needs_info","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-04-20T10:51:29Z","updated_at":"2016-05-14T08:32:21Z","closed_at":null,"body":"##### ISSUE TYPE\r\n - Bug Report\r\n\r\n\r\n##### ANSIBLE VERSION\r\n```\r\nansible 2.1.0 (devel c600ab81ee) last updated 2016/04/20 19:31:25 (GMT +900)\r\n  lib/ansible/modules/core: (detached HEAD a38bdfc720) last updated 2016/04/02 18:12:29 (GMT +900)\r\n  lib/ansible/modules/extras: (detached HEAD 7c3999a92a) last updated 2016/04/02 18:12:48 (GMT +900)\r\n  config file = /Users/techraf/devops/playgrounds/vault-playground/ADHOC/ansible-integration/demo_02_pki_NG/ansible.cfg\r\n  configured module search path = Default w/o overrides\r\n```\r\n\r\n##### CONFIGURATION\r\nVault v0.5.2\r\n\r\n##### OS / ENVIRONMENT\r\nOS X 10.11.4 (15E65)\r\n\r\n##### SUMMARY\r\nThe lookup plugin for `hashi_vault` fails to retrieve CA certificate from path /pki/cert/ca.\r\n```\r\n- debug: msg=\"{{ lookup('hashi_vault', 'secret=pki/cert/ca token={{ vault_token }} url=http://127.0.0.1:8200') }}\"\r\n```\r\nAt the same time the certificate is retrieved successfully with:\r\n\r\n- command-line ```vault read /pki/cert/ca```\r\n- curl ```curl -s -X GET http://127.0.0.1:8200/v1/pki/cert/ca```\r\n- HVAC library ```print(client.read('pki/cert/ca'))```\r\n\r\nAlso, lookup plugin for `hashi_vault` works OK for other secrets:\r\n\r\n```\r\n- debug: msg=\"{{ lookup('hashi_vault', 'secret=secret/hello token={{ vault_token }} url=http://127.0.0.1:8200') }}\"\r\n```\r\n\r\n##### STEPS TO REPRODUCE\r\n```\r\nvault server -dev\r\nexport VAULT_ADDR='http://127.0.0.1:8200'\r\nvault mount pki\r\nvault mount-tune -max-lease-ttl=87600h pki\r\nvault write pki/root/generate/internal common_name=myvault.com ttl=87600h\r\nvault write pki/config/urls issuing_certificates=\"http://127.0.0.1:8200/v1/pki/ca\" crl_distribution_points=\"http://127.0.0.1:8200/v1/pki/crl\"\r\n```\r\nThen run the Ansible task:\r\n```\r\n- debug: msg=\"{{ lookup('hashi_vault', 'secret=pki/cert/ca token={{ vault_token }} url=http://127.0.0.1:8200') }}\"\r\n```\r\n\r\n##### EXPECTED RESULTS\r\n```\r\nok: [localhost] => {\r\n    \"msg\": {\r\n        \"certificate\": \"-----BEGIN CERTIFICATE-----\\nMIIDv....cut....\\nrA==\\n-----END CERTIFICATE-----\\n\"\r\n    }\r\n}\r\n```\r\n\r\n##### ACTUAL RESULTS\r\n```\r\nAn exception occurred during task execution. The full traceback is:\r\nTraceback (most recent call last):\r\n  File \"/usr/local/src/github.com/ansible/lib/ansible/executor/task_executor.py\", line 124, in run\r\n    res = self._execute()\r\n  File \"/usr/local/src/github.com/ansible/lib/ansible/executor/task_executor.py\", line 390, in _execute\r\n    self._task.post_validate(templar=templar)\r\n  File \"/usr/local/src/github.com/ansible/lib/ansible/playbook/task.py\", line 246, in post_validate\r\n    super(Task, self).post_validate(templar)\r\n  File \"/usr/local/src/github.com/ansible/lib/ansible/playbook/base.py\", line 311, in post_validate\r\n    value = templar.template(getattr(self, name))\r\n  File \"/usr/local/src/github.com/ansible/lib/ansible/template/__init__.py\", line 358, in template\r\n    d[k] = self.template(variable[k], preserve_trailing_newlines=preserve_trailing_newlines, fail_on_undefined=fail_on_undefined, overrides=overrides)\r\n  File \"/usr/local/src/github.com/ansible/lib/ansible/template/__init__.py\", line 330, in template\r\n    result = self._do_template(variable, preserve_trailing_newlines=preserve_trailing_newlines, escape_backslashes=escape_backslashes, fail_on_undefined=fail_on_undefined, overrides=overrides)\r\n  File \"/usr/local/src/github.com/ansible/lib/ansible/template/__init__.py\", line 494, in _do_template\r\n    res = j2_concat(rf)\r\n  File \"<template>\", line 8, in root\r\n  File \"/usr/local/lib/python2.7/site-packages/jinja2/runtime.py\", line 196, in call\r\n    return __obj(*args, **kwargs)\r\n  File \"/usr/local/src/github.com/ansible/lib/ansible/template/__init__.py\", line 415, in _lookup\r\n    ran = instance.run(loop_terms, variables=self._available_variables, **kwargs)\r\n  File \"/usr/local/src/github.com/ansible/lib/ansible/plugins/lookup/hashi_vault.py\", line 85, in run\r\n    value = vault_conn.get()\r\n  File \"/usr/local/src/github.com/ansible/lib/ansible/plugins/lookup/hashi_vault.py\", line 66, in get\r\n    return data['data']['value']\r\nKeyError: 'value'\r\n\r\nfatal: [localhost]: FAILED! => {\"failed\": true, \"msg\": \"Unexpected failure during module execution.\", \"stdout\": \"\"}\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/219208260","html_url":"https://github.com/ansible/ansible/issues/15495#issuecomment-219208260","issue_url":"https://api.github.com/repos/ansible/ansible/issues/15495","id":219208260,"user":{"login":"Jorge-Rodriguez","id":4486718,"avatar_url":"https://avatars.githubusercontent.com/u/4486718?v=3","gravatar_id":"","url":"https://api.github.com/users/Jorge-Rodriguez","html_url":"https://github.com/Jorge-Rodriguez","followers_url":"https://api.github.com/users/Jorge-Rodriguez/followers","following_url":"https://api.github.com/users/Jorge-Rodriguez/following{/other_user}","gists_url":"https://api.github.com/users/Jorge-Rodriguez/gists{/gist_id}","starred_url":"https://api.github.com/users/Jorge-Rodriguez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jorge-Rodriguez/subscriptions","organizations_url":"https://api.github.com/users/Jorge-Rodriguez/orgs","repos_url":"https://api.github.com/users/Jorge-Rodriguez/repos","events_url":"https://api.github.com/users/Jorge-Rodriguez/events{/privacy}","received_events_url":"https://api.github.com/users/Jorge-Rodriguez/received_events","type":"User","site_admin":false},"created_at":"2016-05-14T08:32:21Z","updated_at":"2016-05-14T08:32:21Z","body":"@techraf the certificate's value is under the `certificate` key, not under the `value` key, that is why the module is failing.\r\n\r\nYou could submit a feature request to be able to specify the key to retrieve, I have an improvement PR on this plugin, I'd be sure to add it."}}