# Cannot use Gitlab personal access token for SCM

**URL:** <https://forum.ansible.com/t/cannot-use-gitlab-personal-access-token-for-scm/33436>\
**Category:** AWX Project\
**Tags:** awx, ee\
**Created:** [July 20, 2020, 3:03pm UTC](https://forum.ansible.com/t/cannot-use-gitlab-personal-access-token-for-scm/33436 "2020-07-20T15:03:26Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roman](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Roman](https://forum.ansible.com/u/Roman)\
**Post date:** [July 20, 2020, 3:03pm UTC](https://forum.ansible.com/t/cannot-use-gitlab-personal-access-token-for-scm/33436/1 "2020-07-20T15:03:26Z")

</div>

I want my AWX to pull git repository from my private repo in [gitlab.com](http://gitlab.com).

The choice is either SSH key or personal access token. I would prefer access token, so that I could configure read only access.

How to create token in GitLab: [https://docs.gitlab.com/ee/user/profile/personal\_access\_tokens.html#creating-a-personal-access-token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#creating-a-personal-access-token)

In AWX, I can add credential for GitLab [https://docs.ansible.com/ansible-tower/latest/html/userguide/credentials.html#add-a-new-credential](https://docs.ansible.com/ansible-tower/latest/html/userguide/credentials.html#add-a-new-credential)

My AWX v 11.2.0 gives me choice to add “GitLab Personal Access Token”  
But when I create project, and use git for SCM, SCM Credentials choice is blank.

I can add ssh key and use it for git, but would prefer not to use ssh key.

---

<div class="post-metadata">

**Author:** ![Bill\_Nottingham1](https://avatars.discourse-cdn.com/v4/letter/b/58f4c7/32.png) [@Bill\_Nottingham1](https://forum.ansible.com/u/Bill_Nottingham1)\
**Post date:** [July 20, 2020, 4:54pm UTC](https://forum.ansible.com/t/cannot-use-gitlab-personal-access-token-for-scm/33436/2 "2020-07-20T16:54:51Z")

</div>

Roman Terescenko (invizus@gmail.com) said:

> I want my AWX to pull git repository from my private repo in gitlab.com.
> 
> The choice is either SSH key or personal access token. I would prefer  
> access token, so that I could configure read only access.
> 
> How to create token in GitLab:  
> [https://docs.gitlab.com/ee/user/profile/personal\_access\_tokens.html#creating-a-personal-access-token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#creating-a-personal-access-token)

> From the top of this doc:

&nbsp;&nbsp;You can also use personal access tokens with Git to authenticate over HTTP  
&nbsp;&nbsp;or SSH. ... In both cases, you can authenticate with a token in place  
&nbsp;&nbsp;of your password.

Ergo, use it as a password in a SCM credential.

Bill

---

<div class="post-metadata">

**Author:** ![Roman](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Roman](https://forum.ansible.com/u/Roman)\
**Post date:** [July 21, 2020, 10:28am UTC](https://forum.ansible.com/t/cannot-use-gitlab-personal-access-token-for-scm/33436/3 "2020-07-21T10:28:35Z")

</div>

What is “GitLab Personal Access Token” used for? I cannot find any other use for it in AWX.

[https://docs.ansible.com/ansible-tower/latest/html/userguide/credentials.html#gitlab-personal-access-token](https://docs.ansible.com/ansible-tower/latest/html/userguide/credentials.html#gitlab-personal-access-token)

---

<div class="post-metadata">

**Author:** ![Roman](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Roman](https://forum.ansible.com/u/Roman)\
**Post date:** [July 21, 2020, 1:05pm UTC](https://forum.ansible.com/t/cannot-use-gitlab-personal-access-token-for-scm/33436/4 "2020-07-21T13:05:53Z")

</div>

I may have misunderstood the purpose of tokens. [https://www.ansible.com/blog/using-ansible-automation-platform-gitlab-ce-and-webhooks-to-deploy-iis-website](https://www.ansible.com/blog/using-ansible-automation-platform-gitlab-ce-and-webhooks-to-deploy-iis-website)

Then I will have no choice but to setup SSH access to git.

---

<div class="post-metadata">

**Author:** ![Roman](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Roman](https://forum.ansible.com/u/Roman)\
**Post date:** [July 21, 2020, 1:09pm UTC](https://forum.ansible.com/t/cannot-use-gitlab-personal-access-token-for-scm/33436/5 "2020-07-21T13:09:17Z")

</div>

If SSH is the only way to retrieve git into AWX, then this may not work with my security controls, allowing - outgoing ssh connections.

---

<div class="post-metadata">

**Author:** ![sdmorel](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@sdmorel](https://forum.ansible.com/u/sdmorel)\
**Post date:** [July 22, 2020, 6:10am UTC](https://forum.ansible.com/t/cannot-use-gitlab-personal-access-token-for-scm/33436/6 "2020-07-22T06:10:40Z")

</div>

Hello,

When you create a project in AWX, make sure to use the HTTPS url from your Gitlab repository, that way AWX will use HTTPS and not SSH when cloning the repository.  
But, if you don’t want to use SSH, how are you connecting to your inventory hosts to run Ansible?

---

<div class="post-metadata">

**Author:** ![Roman](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Roman](https://forum.ansible.com/u/Roman)\
**Post date:** [July 22, 2020, 8:29am UTC](https://forum.ansible.com/t/cannot-use-gitlab-personal-access-token-for-scm/33436/7 "2020-07-22T08:29:23Z")

</div>

I have figured it out. It is not ideal because API token is stored in clear and anyone with access to AWX can see it. I am not comfortable with this approach but looks like it is the only one apart from SSH key.

1. create personal access token with read\_repository permissions: [https://docs.gitlab.com/ee/user/profile/personal\_access\_tokens.html#creating-a-personal-access-token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#creating-a-personal-access-token)
2. create project, SCM type: Git
3. paste URL, it should look like: `https://gitlabusername:personal_access_token@gitlab.com/group/privateproject.git`

---

<div class="post-metadata">

**Author:** ![Wei-Yen\_Tan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wei-yen_tan/32/4111_2.png) [@Wei-Yen\_Tan](https://forum.ansible.com/u/Wei-Yen_Tan)\
**Post date:** [July 22, 2020, 8:33am UTC](https://forum.ansible.com/t/cannot-use-gitlab-personal-access-token-for-scm/33436/8 "2020-07-22T08:33:08Z")

</div>

Just clarifying Are you trying to do this as a awx project?

---

<div class="post-metadata">

**Author:** ![Roman](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Roman](https://forum.ansible.com/u/Roman)\
**Post date:** [July 22, 2020, 8:59am UTC](https://forum.ansible.com/t/cannot-use-gitlab-personal-access-token-for-scm/33436/9 "2020-07-22T08:59:13Z")

</div>

Yes

---

<div class="post-metadata">

**Author:** ![Wei-Yen\_Tan](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/wei-yen_tan/32/4111_2.png) [@Wei-Yen\_Tan](https://forum.ansible.com/u/Wei-Yen_Tan)\
**Post date:** [July 22, 2020, 9:04am UTC](https://forum.ansible.com/t/cannot-use-gitlab-personal-access-token-for-scm/33436/10 "2020-07-22T09:04:43Z")

</div>

If I am right your gitlab token is just in the password of the credential object with your username being the same.

That’s how I have used my token currently. I have one on my user account because i use 2fa

---

<div class="post-metadata">

**Author:** ![sdmorel](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@sdmorel](https://forum.ansible.com/u/sdmorel)\
**Post date:** [July 22, 2020, 9:09am UTC](https://forum.ansible.com/t/cannot-use-gitlab-personal-access-token-for-scm/33436/11 "2020-07-22T09:09:56Z")

</div>

That’s right, you store your token in the password field of a SCM credential and use that credential to update the project in AWX.

---

<div class="post-metadata">

**Author:** ![Roman](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Roman](https://forum.ansible.com/u/Roman)\
**Post date:** [July 22, 2020, 9:14am UTC](https://forum.ansible.com/t/cannot-use-gitlab-personal-access-token-for-scm/33436/12 "2020-07-22T09:14:39Z")

</div>

Thanks, that’s right, it worked for me.

I stored my personal access token in Credentials, credential type: Source Control
