'How can I use ansible.builtin.git for creating local branch and pushing code to git repo?

I need to perform the following steps in using ansible playbook:

  1. I need to clone a repository,
  2. Make some changes to a file in that repository
  3. Checkout the changes to a new branch locally
  4. Commit the change and push to remote repository

For cloning I am able to do this

 - name: CloneTeamRepoisitory
   ansible.builtin.git:
    repo: '[email protected]:myrepo/my-team.git'
    dest: '{{ TMPDIR }}'
    clone: yes
    update: no
    accept_hostkey: yes

After this I make some file changes through copy command

Now I need to checkout to a git branch locally the changes I did in the previous step:

### if it's the first time you are using this customer's branch:
git checkout -b <teamname>
#### all subsequent times
git checkout <teamname>
####
git add <teamname>
git commit -m "Adding team <newteamname>"
### First time push
git push --set-upstream origin <team>
### Afterwards first time subsequent push:
git push

For this step, I am not aware I can do it with the ansible.builtin.git module. Is there any way I can accomplish my requirement using a dedicated Ansible module?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source