It's simpler to write your YAML
variable definitions and values as you normally do, then pass the
"sensitive" ones through a filter that takes care of the fiddly
details. Let's start with the same YAML data as in the example
above, and use vim on [redacted]
to edit it. Again, you should have your ANSIBLE_VAULT_IDENTITY and
ANSIBLE_VAULT_IDENTITY_LIST environment variables set. Here's the
procedure:
vim.shift-v".
Your current line should highlight.:". You should be
presented with a prompt like ":'<,'>"
which represents the range of selected lines that you
want to operate on.!av-filter" and
hit enter. This will pipe the selected
lines through the "av-filter" command,
replacing the original line with the av-filter's
output. (Use "!av-filter xxxx"
if you don't have your ANSIBLE_VAULT_IDENTITY
environment variable set, but you do have an "xxxx"
vault identity.)ansible-vault is no speed
daemon.Your selected data should be
replaced with the ansible-vault encrypted version of
the same string, i.e. the blue bits from the section above. If
things messed up and you got error messages, read them,
then hit "u" to invoke vim's "undo"
command. That should put things as they were, and you can go and
think about just what you have done.
The same procedure will unvault
the value if it's already vaulted. That "!vault"
is a YAML tag that indicates the data type; av-filter
always encrypts strings and decrypts "!vault", so you never have
to tell it whether to encrypt or decrypt. On the back-end of
course it's invoking ansible-vault for you and
handling the data transfers in and out.
Also, av-filter
is in the /[redacted]/bin directory. If
that's not in your path, you've got more work to do. It's a short
python script which you can copy to your workstation if you like.
(And you get a free trip to pip hell out of it.)