Skip to content

Instantly share code, notes, and snippets.

@metalrufflez
Created March 13, 2018 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metalrufflez/344a138b7ab693cd4e70d0dafe59b6f3 to your computer and use it in GitHub Desktop.
Save metalrufflez/344a138b7ab693cd4e70d0dafe59b6f3 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# ansible-vault-merge: helper script for merging changes in ansible-vault file
#
PROGNAME=$(basename $0)
usage() {
cat <<EOF
usage: ${PROGNAME} [OPTION]... [--] BASE CURRENT OTHER [LOCATION]
-h, --help Display this help
EOF
}
while test $# -gt 0; do
case $1 in
--help|-h)
usage
exit 0
;;
--)
shift 1
break
;;
-*)
echo "${PROGNAME}: unknown option $1" >&2
usage >&2
exit 1
;;
*)
# probably the first positional argument
break
esac
done
if test $# -lt 3; then
echo "${PROGNAME}: not enough arguments" >&2
usage >&2
exit 1
fi
BASE=$1
CURRENT=$2
OTHER=$3
LOCATION=$4
set -e
echo "ansible-vault-merge ${LOCATION}"
ansible-vault decrypt $BASE > /dev/null
ansible-vault decrypt $CURRENT > /dev/null
ansible-vault decrypt $OTHER > /dev/null
if ! git merge-file -L CURRENT -L BASE -L OTHER $CURRENT $BASE $OTHER; then
echo "Merge conflict; opening editor to resolve." >&2
vimdiff $CURRENT $OTHER $BASE
fi
ansible-vault encrypt $CURRENT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment