Ansible Tower - How to get Credentials of type 'Github Personal Access Token' into a playbook?

873 Views Asked by At

I have my GitHub Personal Access Token (PAT) stored as a credential in Ansible Tower.

How can I reference this value in my playbook?

I've searched for examples for other Credential Types like "How to use Ansible Tower login credentials in playbook?", but I haven't found one for my use case.

The official documentation also doesn't seem to have examples of how to use this type in a playbook.

Below is an example on how to use "AWS Credential" in a playbook.

vars:
  aws:
    access_key: '{{ lookup("env", "AWS_ACCESS_KEY_ID") }}'
    secret_key: '{{ lookup("env", "AWS_SECRET_ACCESS_KEY") }}'
    security_token: '{{ lookup("env", "AWS_SECURITY_TOKEN") }}'

Similarly there should be a syntax for "Github Personal Access Token" credential too but I'm unable to find that info. Ideally it should look something like below

vars:
  git:
    token: '{{ lookup("env", "GITHUB_PAT") }}'
1

There are 1 best solutions below

0
U880D On

Similarly there should be a syntax for Github Personal Access Token credential too

In understand your question as "How to find out the name from a Credential of type Github Personal Access Token within the Ansible Tower Environment (env) as that (name) is not referenced in documentation?"

After reading the Ansible Tower documentation about Credentials - Github Personal Access Token (PAT)

This credential can be used for establishing an API connection to GitHub for use in Webhook Listener Jobs, to post status updates.

and setting up a short test according Credentials - Getting Started with Credentials by using

NAME: PAT
CREDENTIAL TYPE: GitHub Personal Access Token

and Create a Job Template,

I found this KIND of Credential not referenceable for a Job Template and as the documentation states. This will prevent from Debugging Credential Types.

The official documentation also doesn't seem to have examples of how to use this in a playbook.

This will most likely be the reason why it is not mentioned within the documentation, as well not under Multi-Credential Assignment and will lead you to the option of using a Credential of type Custom Credential Types.

To summarize

How to get Credentials of type 'Github Personal Access Token' into a playbook? ... How can I reference this value in my playbook?

You can't.