Seems like there is isn’t any module in Ansible which can commit back to a GIT repo. My case is such that i am allowing the user to create a new branch in any of our several repositories and with the help of templates, generate some necessary files, all this via ansible. I am able to clone the repo (even a branch/tag) via GIT module, create a new branch with shell module, populate it with templates, but now i need to push the new branch and its contents and this is where i am stuck. GIT push would prompt for username and password which is something i have in the variables but don’t know how to use in Ansible shell command. Any ideas how to proceed here ?
I think something like the below would work to solve your problem with the variable interpolation.
`
- name: Push git commits with local variables.
hosts: localhost
vars:
username: git_username
password: git_password
tasks:
- name: Set origin to include username and password.
shell: “git remote set-url origin https://{{ git_username }}:{{ git_password }}@yourhost.com/storage/repo.git”
- name: Push to origin.
shell: “git push origin branch”
`
That is, if you can safely transmit the passwords via https. If you’re using http this would be incredibly unsafe.
You could also look at setting the credential.helper variable in git (git config --global credential.helper store
), but that’s beyond the scope of this mailing list.
I found a single GIT command to do that.
git push origin <tag/branch> --repo https://username:pass@repourl.com