1

A developer just finished making changes to some code on a Dev server that received a git clone from an Azure git Repository using Ansible.

What specific syntax must be used in Ansible tasks to add, commit, and push the developer's changed code from the Dev server back to the same Azure git Repository?

The following is the git clone Ansible task that was contributed by @garylopez:

--- 
- name: Clone repo playbook
  hosts: dev

  vars_prompt: 
    - name: "git_password" 
      prompt: "Password for 'https://OrganizationName@dev.azure.com'"
      private: yes 

  tasks:
  - name: Clone a repo 
    git:
      repo: https://{{ git_user | urlencode }}:{{ git_password | urlencode }}@dev.azure.com/OrganizationName/ProjectName/_git/RepositoryName
      dest: /src/RepositoryName  

We have examined the Ansible git module's docs, but do not see a boilerplate example.

We imagine someone might resort to some sort of shell command solution in Ansible tasks if the Ansible git module does not support this. But we are asking here hoping that a best practice type approach might be offered in an answer.

Carlos
  • 128
  • 5
CodeMed
  • 9,527
  • 70
  • 212
  • 364
  • 1
    The `git` module will only let you get a fresh clone of a remote repository for deployment purpose. There have been several temptatives to provide add/commit/push functionalities to ansible, either by adding to the existing module or providing a new one (one example: https://github.com/ansible-collections/community.general/pull/168). But none made it up to a release to my knowledge. For now, you will have to go the command/shell route. – Zeitounator Nov 05 '20 at 09:44

1 Answers1

1

you can use git module for checkout and shell command for add commit push https://docs.ansible.com/ansible/latest/collections/ansible/builtin/git_module.html

  • No, I'm pretty sure you can't. Looking at the git_module link you've posted, the module description says "Manage git checkouts of repositories to deploy files or software" - so no mention of updating repos, and no such parameters are availble. I'd be happy to be proved wrong, but it does look like you've misunderstood this module (also see Zeitounator's comment on the question) – Andrew Richards Feb 20 '22 at 17:55