How to do a git pull/push using ansible

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: [email protected]: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.


It should be like:-

tasks: - name: pull from git git: repo: [email protected]:xyz.git dest: /root/Development/abc update: yes version: master

Note: Here the remote user is root