Git Product home page Git Product logo

Comments (5)

jhaals avatar jhaals commented on June 26, 2024

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.

danielmotaleite avatar danielmotaleite commented on June 26, 2024

Ok, so if its the same behaviour, i guess its OK :)

thanks for the help!

from ansible-vault.

danielmotaleite avatar danielmotaleite commented on June 26, 2024

while other lookup also have the problem, i just found by accident that not all agree that simply fail is the best option:

ansible/ansible#28908

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.

danielmotaleite avatar danielmotaleite commented on June 26, 2024

@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.

strangeman avatar strangeman commented on June 26, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.