# Playbook hangs while doing a git commit

**URL:** <https://forum.ansible.com/t/playbook-hangs-while-doing-a-git-commit/10311>\
**Category:** Get Help\
**Tags:** git, playbook, ee\
**Created:** [October 15, 2024, 6:34pm UTC](https://forum.ansible.com/t/playbook-hangs-while-doing-a-git-commit/10311 "2024-10-15T18:34:33Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ken\_Arnold](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ken_arnold/32/5167_2.png) [@Ken\_Arnold](https://forum.ansible.com/u/Ken_Arnold)\
**Post date:** [October 15, 2024, 6:34pm UTC](https://forum.ansible.com/t/playbook-hangs-while-doing-a-git-commit/10311/1 "2024-10-15T18:34:33Z")

</div>

My playbook hangs while trying to do a commit. Sometimes when I hit cancel on the job it comes back with a “Username for ‘https://\<gitlab\_url\>’:”. I’m trying to run this playbook within an Execution Environment. I don’t run into the same problem when running it outside of the playbook.

Here is the code where it is hanging:

- name: Commit changes to repo on branch {{ branch }}  
shell:  
cmd: “git add . && git commit -m ‘Upgraded {{ majorVersion }} to {{ version }}’ && git push origin {{ branch }}”  
chdir: “{{ repo\_dir }}”  
register: out

I’m not sure if it is expecting a Gitlab username at this point or if it is hanging on something else. I set both the git global user email and username just before running this code. Any ideas?

---

<div class="post-metadata">

**Author:** ![binbashroot](https://avatars.discourse-cdn.com/v4/letter/b/ad7895/32.png) [@binbashroot](https://forum.ansible.com/u/binbashroot)\
**Post date:** [October 15, 2024, 11:11pm UTC](https://forum.ansible.com/t/playbook-hangs-while-doing-a-git-commit/10311/2 "2024-10-15T23:11:07Z")

</div>

You’ll need to setup a custom credential and call the ssh key file as an injector to be used as part of your git push.

---

<div class="post-metadata">

**Author:** ![jiholland](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jiholland/32/11273_2.png) [@jiholland](https://forum.ansible.com/u/jiholland)\
**Post date:** [October 16, 2024, 10:38am UTC](https://forum.ansible.com/t/playbook-hangs-while-doing-a-git-commit/10311/3 "2024-10-16T10:38:43Z")

</div>

> [@Ken\_Arnold](#):
>
> Sometimes when I hit cancel on the job it comes back with a “Username for ‘https://\<gitlab\_url\>’:”

It is prompting for credentials which you have probably not provided.

```yaml
$ git push https://<username>:<access_token_or_password>@<gitlab_url>

```

If you do something like that you should use the [no\_log](https://docs.ansible.com/ansible/latest/reference_appendices/logging.html) option to not log sensitive data.

> [@Ken\_Arnold](#):
>
> I set both the git global user email and username just before running this code

Thats good: you might also be able to use the [community.general.git\_config](https://docs.ansible.com/ansible/latest/collections/community/general/git_config_module.html#ansible-collections-community-general-git-config-module) module to add credentials.

Another option is to use ssh instead of https and simply add the ssh private key to your credential in AWX and it should be “mounted” in the EE when running playbooks.

---

<div class="post-metadata">

**Author:** ![Ken\_Arnold](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ken_arnold/32/5167_2.png) [@Ken\_Arnold](https://forum.ansible.com/u/Ken_Arnold)\
**Post date:** [October 17, 2024, 10:09pm UTC](https://forum.ansible.com/t/playbook-hangs-while-doing-a-git-commit/10311/4 "2024-10-17T22:09:08Z")

</div>

I would rather do the ssh option instead of https. I setup “GitLab Private Key” credentials within AAP. I might not be mounting this correctly. I’ve setup the mounting through “Settings | Job Settings | Paths to expose to isolated jobs” in AAP like “/home/gitlab\_user/.ssh:/runner/project/.ssh:O”. Is there a different way I should be mounting it?

---

<div class="post-metadata">

**Author:** ![jiholland](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jiholland/32/11273_2.png) [@jiholland](https://forum.ansible.com/u/jiholland)\
**Post date:** [October 18, 2024, 5:37am UTC](https://forum.ansible.com/t/playbook-hangs-while-doing-a-git-commit/10311/5 "2024-10-18T05:37:34Z")

</div>

You should use [machine credentials](https://docs.ansible.com/automation-controller/latest/html/userguide/credentials.html#machine). Add the ssh private key to the machine credential and use the credential when launching the template in AAP.

---

<div class="post-metadata">

**Author:** ![Ken\_Arnold](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ken_arnold/32/5167_2.png) [@Ken\_Arnold](https://forum.ansible.com/u/Ken_Arnold)\
**Post date:** [October 18, 2024, 3:37pm UTC](https://forum.ansible.com/t/playbook-hangs-while-doing-a-git-commit/10311/6 "2024-10-18T15:37:28Z")

</div>

Tried it with machine credentials. Still hanging… Does that mount look correct? “/home/gitlab\_user/.ssh:/runner/project/.ssh:O” I’m trying other options there to see if it needs to be something like /root/.ssh or something else but when I do a “cd ~” and “pwd” as a test in my playbook I get back /runner/project.

---

<div class="post-metadata">

**Author:** ![jiholland](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jiholland/32/11273_2.png) [@jiholland](https://forum.ansible.com/u/jiholland)\
**Post date:** [October 18, 2024, 3:49pm UTC](https://forum.ansible.com/t/playbook-hangs-while-doing-a-git-commit/10311/7 "2024-10-18T15:49:16Z")

</div>

You don’t have to do any of that: it’s passed as an option, not mounted. [11. Credentials — Automation Controller User Guide v4.5](https://docs.ansible.com/automation-controller/latest/html/userguide/credentials.html#machine)

---

<div class="post-metadata">

**Author:** ![Ken\_Arnold](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ken_arnold/32/5167_2.png) [@Ken\_Arnold](https://forum.ansible.com/u/Ken_Arnold)\
**Post date:** [October 18, 2024, 10:02pm UTC](https://forum.ansible.com/t/playbook-hangs-while-doing-a-git-commit/10311/8 "2024-10-18T22:02:26Z")

</div>

That seems pretty simple. Create the machine credentials and add them to the template. The playbook still hangs at the commit point looking for a username. What might I be missing?

---

<div class="post-metadata">

**Author:** ![jiholland](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jiholland/32/11273_2.png) [@jiholland](https://forum.ansible.com/u/jiholland)\
**Post date:** [October 19, 2024, 6:04am UTC](https://forum.ansible.com/t/playbook-hangs-while-doing-a-git-commit/10311/9 "2024-10-19T06:04:35Z")

</div>

And you changed from https to ssh when you clone the repo?

---

<div class="post-metadata">

**Author:** ![Ken\_Arnold](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ken_arnold/32/5167_2.png) [@Ken\_Arnold](https://forum.ansible.com/u/Ken_Arnold)\
**Post date:** [October 21, 2024, 7:28pm UTC](https://forum.ansible.com/t/playbook-hangs-while-doing-a-git-commit/10311/10 "2024-10-21T19:28:27Z")

</div>

Thank you. I’d forgotten that I’d set that to https when I was struggling to get the ssh clone to work. I appreciate all your help.

---

<div class="post-metadata">

**Author:** ![jiholland](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jiholland/32/11273_2.png) [@jiholland](https://forum.ansible.com/u/jiholland)\
**Post date:** [October 21, 2024, 7:36pm UTC](https://forum.ansible.com/t/playbook-hangs-while-doing-a-git-commit/10311/11 "2024-10-21T19:36:51Z")

</div>

No problem. Glad I could help.
