Scenario / Questions

I am trying to do a git pull/push using ansible.
I am running ansible on one server and want to automate or orchestrate a git pull/push on a remote host.

Now since i didn’t find a mmodule to do this on ansible doc website, i decided to go the script route using the script module

The problem is ansible hags when it gets to running the git pull called in the script

Anyone know how to run git pull/push using ansible?

Thanks

Find below all possible solutions or suggestions for the above questions..

Suggestion: 1

Ansible’s Git Module will do this for you as far as the “pull” is concerned, just make sure that the user that is running the command has key-based access to the git repo.

You can specify the user that the command runs as by adding the “sudo_user” parameter to your task:

- name: Get stuff from git
  git: repo=git@github.com:you/your-git-repo.git dest=/opt/git-stuff
  sudo_user: <your user that has the ssh key>

See https://docs.ansible.com/playbooks_intro.html for more information on using sudo_user.

Suggestion: 2

It should be like:-

tasks:
- name: pull from git
git:
repo: git@gitlab.com:xyz.git
dest: /root/Development/abc
update: yes
version: master

Note: Here the remote user is root

Suggestion: 3

you can try this

- git:
    repo: 'https://foosball.example.org/path/to/repo.git'
    dest: /srv/checkout
    version: release-0.22

full documentation on https://docs.ansible.com/ansible/latest/modules/git_module.html