Search code examples
ansible-vault

Ansible-vault does not escape data starting with a dash


ansible-vault encrypt_string '--IcannotCh@ngeThisPassword'

This command gives the following error. So it tries to read it as a normal arg.

ansible-vault: error: unrecognized arguments: --IcannotCh@ngeThisPassword

What is the correct way to escape this? I tried:

  • single quotes ''
  • double quotes ""
  • Tildes ``

But slashes \ / these get prefixed to the password like:
\--IcannotCh@ngeThisPassword

What is the proper way to encrypt this?


Solution

  • This is not an issue with ansible-vault, this is general 'shell argument passing', the way to escape it is --

    ansible-vault encrypt_string -- '--IcannotCh@ngeThisPassword'
    

    Source