Skip to content

Instantly share code, notes, and snippets.

@boznius
Created April 12, 2017 07:32
Show Gist options
  • Save boznius/ebd49607df11b8054c497ab94f30537a to your computer and use it in GitHub Desktop.
Save boznius/ebd49607df11b8054c497ab94f30537a to your computer and use it in GitHub Desktop.
encrypt all files in a directory with ansible-vault
for i in $(find . -type f); do ansible-vault encrypt $i --vault-password-file ~/.vault && echo $i encrypted ; done
@atb00ker
Copy link

Thank You. πŸ‘
Here is an alternative just incase someone finds it helpful. 😊

find . -type f -printf "%h/\"%f\" " | xargs ansible-vault encrypt

@TimeTravelersHackedMe
Copy link

@atb00ker

Thank You. πŸ‘
Here is an alternative just incase someone finds it helpful. 😊

find . -type f -printf "%h/\"%f\" " | xargs ansible-vault encrypt

This one works for files with spaces in their name

@jdotsmith
Copy link

What about a command to vault all files named something.yml?

For instance:

group_vars > all > all.yml, password.yml
group_vars > test > test.yml, password.yml

Looking to vault all the password.yml files under those folders, and not have to do them one by one.

@atb00ker
Copy link

Find can be used to specify the name of the file as well!
Checkout here: https://stackoverflow.com/a/5905066
Doing this recursively might do the trick.

@boznius
Copy link
Author

boznius commented Apr 16, 2021

@jdotsmith What you are looking for looks like this :

for i in $(find . -name password.yml); do ansible-vault encrypt $i  --vault-password-file ~/.vault && echo $i encrypted ; done

But you will need to adjust it of course.

@xJuggl3r
Copy link

xJuggl3r commented Jun 24, 2021

Why not simply ansible-vault encrypt dir/* --vault-password-file ~/.vault for all files in a folder?

@EtsuNDmA
Copy link

Why not simply ansible-vault encrypt dir/* --vault-password-file ~/.vault for all files in a folder?

this doesn't work with nested dirs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment