Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Ansible git module pull a branch with local changes?

My git workspace is dirty, there are some local modifications. When I use command git pull origin master it works fine because there is no conflict.

But when I'm trying to use Ansible like git: repo=xxxx dest=xxx version={{branch}} I got error:

Local modifications exist in repository (force=no)

If I add force=yes, then I will lose my local modifications.

What can I do to keep my local changes and pull latest commit from git by using Ansible git module.

like image 470
TommyTT Avatar asked Dec 16 '16 06:12

TommyTT


People also ask

How do you use Ansible pull?

The ansible-pull command, which is part of Ansible, allows you to download your configuration from a Git repository and apply it immediately. You won't need to maintain a server or an inventory list; you simply run the ansible-pull command, feed it a Git repository URL, and it will do the rest for you.


2 Answers

You cannot achieve it using the git module.

Ansible checks the result of:

git status --porcelain

and aborts task execution if there are local changes in tracked files, unless force parameter is set to true.

like image 169
techraf Avatar answered Sep 25 '22 19:09

techraf


You can use something like :

git: repo=xxxx dest=xxx version={{branch}} force=no
ignore_errors: yes

see https://docs.ansible.com/ansible/latest/user_guide/playbooks_error_handling.html#ignoring-failed-commands

like image 26
Clément Mondon Avatar answered Sep 23 '22 19:09

Clément Mondon