Playbook hangs while doing a git commit

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?

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.

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

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

If you do something like that you should use the no_log option to not log sensitive data.

Thats good: you might also be able to use the community.general.git_config 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.

2 Likes

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?

You should use machine credentials. Add the ssh private key to the machine credential and use the credential when launching the template in AAP.

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.

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

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?

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

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.

1 Like

No problem. Glad I could help.