Comments (5)
Hi,
Lookup plugins like file
has the same behaviour and will fail when trying to lookup a file that does not exist. I want this plugin to work in a similar way as the built-in lookup plugins
- hosts: localhost
connection: local
gather_facts: False
tasks:
- name: Get a secret from Vault
~_ debug: msg="{{ lookup('file', 'user_data_file') | default('')}}"
~/src/ansible-vault/tests(master ✗) ansible-playbook test-playbook.yaml
[WARNING]: Host file not found: /etc/ansible/hosts
[WARNING]: provided hosts list is empty, only localhost is available
PLAY [localhost] **********************************************************************************************************************************************************
TASK [Get a secret from Vault] ********************************************************************************************************************************************
[WARNING]: Unable to find 'user_data_file' in expected paths.
fatal: [localhost]: FAILED! => {"failed": true, "msg": "An unhandled exception occurred while running the lookup plugin 'file'. Error was a <class 'ansible.errors.AnsibleError'>, original message: could not locate file in lookup: user_data_file"}
to retry, use: --limit @/Users/jhaals/src/ansible-vault/tests/test-playbook.retry
PLAY RECAP ****************************************************************************************************************************************************************
localhost : ok=0 changed=0 unreachable=0 failed=1
~/src/ansible-vault/tests(master ✗) ansible --version
ansible 2.3.2.0
config file = /Users/jhaals/src/ansible-vault/tests/ansible.cfg
configured module search path = Default w/o overrides
python version = 2.7.13 (default, Jul 31 2017, 13:30:25) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]
from ansible-vault.
Ok, so if its the same behaviour, i guess its OK :)
thanks for the help!
from ansible-vault.
while other lookup also have the problem, i just found by accident that not all agree that simply fail is the best option:
The File lookup may be logic to fail if the file is missing, but like passwordstore lookup, in vault lookup may be more friendly to have a option to ignore the missing key as they are possibly mode dynamic lookups
from ansible-vault.
@jhaals please reopen this as this limits a lot the ansible<->vault usage
We want to store some private keys in the vault, but if they are missing, ansible would create then and upload to vault. We can not do this because right now, if the key is missing, the ansible will abort, forcing the manual creation of keys
Please add the "ok_if_missing" option, so we can test if a value exists in vault, even if File lookup aborts
It does not look as a hard change, If we do this and submit a pull request, would you accept it?
from ansible-vault.
@danielmotaleite sorry for necroposting, but {{ lookup('vault', 'secret/ansible/missing_variable', 'value', errors='ignore') or "some_default_value" }}
works for me
from ansible-vault.
Related Issues (20)
- Error retrieving data from vault HOT 1
- Allow to iterate over list of secrets not values HOT 1
- is there a plan to add support to VAULT_GITHUB_API_TOKEN? HOT 1
- CERTIFICATE_VERIFY_FAILED HOT 2
- Delay lookups HOT 4
- Quoted parameters should not be split on spaces HOT 1
- Install instructions? HOT 3
- Handle API endpoints that don't return JSON
- Errors with lookup HOT 3
- Python Crashes when using this Plugin in OSX High Sierra HOT 8
- Cache not used
- Using Python 3.6.4 Unable to retrieve personal token from vault: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str. HOT 2
- Test play using vault plugin fails HOT 1
- Multipart Dynamic secrets are not cached in Playbooks HOT 1
- Inserting variables into a pki lookup statement
- Integration with molecule test 'object has no attribute 'code' HOT 2
- Failing AppRole Authentication
- Unhandled exception with the newest jinja and ansible
- dont support kv-v2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ansible-vault.