Diff and merge ansible vaults via git easily
Go to file
Jan Veen 0ecd41ed5f
Fix indentation
2024-02-18 09:06:31 +01:00
pkg/Archlinux Simplify build of local directory 2019-11-29 12:04:16 +01:00
.gitignore Simplify build of local directory 2019-11-29 12:04:16 +01:00
LICENSE Initial commit 2018-11-05 21:42:48 +01:00
README.md Fix indentation 2024-02-18 09:06:31 +01:00
ansible-vault Add original name to temporary merge files 2019-10-05 12:09:45 +02:00

README.md

Ansible vault git integration

Enable displaying diffs and merging ansible vaults in git.

Interactive password input is not supported

Installation

  • Copy the ansible-vault script to your_script_directory

  • Configure git to use the script by adding this to ~/.gitconfig or .git/config (projectwise):

[diff]
    tool = ansible-vault
[difftool "ansible-vault"]
    cmd = your_script_directory/ansible-vault diff \"$REMOTE\" \"$LOCAL\" \"$MERGED\" \"$BASE\"
[diff "ansible-vault"]
    command = your_script_directory/ansible-vault diffdriver
[merge]
    tool = ansible-vault
[mergetool "ansible-vault"]
    cmd = your_script_directory/ansible-vault merge \"$REMOTE\" \"$LOCAL\" \"$MERGED\" \"$BASE\"

Now the tool is available in git difftool and git mergetool.

  • (Optional) To enable inline support for git diff tell git how to generate diffs for your files. Create a .gitattributes file in the git root directory and mark the vault files as diffable, e.g.: *_vault.yml diff=ansible-vault.

Merging files

When using the script as mergetool make sure to merge to the RIGHT direction.

Finding your ansible.cfg

The script looks for your ansible configuration file to resolve vault ids and secret locations. When diffing root/bar/tool_vault.yml the script probes root/bar/ansible.cfg and root/ansible.cfg for your actual file. If none is found it asks for a path interactively.