DEV Community

David Ngugi
David Ngugi

Posted on

Resolve merge conflicts in ansible vault

When you use ansible vault in your project, sometimes merge conflicts would occur across divergent branches that make changes to the encrypted file. Below is a simple process to identify and resolve merge conflicts introduced in an ansible vault file.

Step 1: Decrypt the vault

For each of the divergent branches, decrypt the vault so that you can have a readable text file

git checkout master
git pull
ansible-vault decrypt secrets-file
git commit -am "decrypting vault to better handle merge conflicts"

git checkout my-new-branch
git pull
ansible-vault decrypt secrets-file
Enter fullscreen mode Exit fullscreen mode

Step 2: Start Merge operation

You can now attempt to merge one branch into the other based on your preferred strategy

git merge master
Auto-merging secrets-file
CONFLICT (content): Merge conflict in secrets-file
Automatic merge failed; fix conflicts and then commit the result.

Enter fullscreen mode Exit fullscreen mode

Open your favourite IDE and resolve the merge conflicts presented

Resolving Merge conflicts with IDE

Complete the merge

git add secrets-file
git commit -m "Resolved merge conflicts"
Enter fullscreen mode Exit fullscreen mode

Step 3: Clean up

Now that you have resolved your merge conflicts locally, encrypt the update secret file

ansible-vault encrypt secrets-file
Enter fullscreen mode Exit fullscreen mode

And clean up your other branch

git checkout master
git reset --hard origin/master
Enter fullscreen mode Exit fullscreen mode

Encrypt

Step 4: Push to remote(optional)

If done working on your branch, you can push all your merged changes to remote

git checkout my-new-branch
git push
Enter fullscreen mode Exit fullscreen mode

Top comments (0)