0

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") }}'
U880D
  • 8,601
  • 6
  • 24
  • 40
vishal
  • 1,646
  • 5
  • 28
  • 56
  • Does [Ansible Tower - How to pass Machine credentials as an `--extra-vars` to the Job Template?](https://stackoverflow.com/a/71030474/6771046) or [Ansible Tower: Custom Credential Type](https://stackoverflow.com/a/73422397/6771046) answer your question? – U880D Jun 16 '23 at 09:42
  • @U880D Nope unfortunately. They all talk about how to pass the credentials but none of them have an syntax example for GIT PAT token. Unable to find one from official doc too. Ideally Official doc should be providing these – vishal Jun 16 '23 at 09:46
  • That's strange, because it is answering your question for me and the linked examples, as well the official documentation showing me how to use it. So I like to understand what is your question or where do you struggle? – U880D Jun 16 '23 at 09:50
  • @U880D I've added more info to the question on what I'm looking for. this should give you the context – vishal Jun 16 '23 at 09:58
  • But all links are answering the question already (... at least for me). I agree that the documentation is no so easy to read that I can just skim them. "_Similarly there should be a syntax for "Github Personal Access Token (PAT)" credential too_", no, that's just a name for a data structure. If you like to have a credential with such (name) I like to recommend to use the Custom Credential Type and name it accordingly. – U880D Jun 16 '23 at 10:03
  • @U880D Nope, Github Personal Access Token is an offical defined credential type available in Ansible Tower. https://docs.ansible.com/ansible-tower/latest/html/userguide/credentials.html#github-personal-access-token One should go for custom credential only when the type of credential they require is not already supported by Ansible Tower – vishal Jun 16 '23 at 10:06
  • So what is the question then? If it is already there, just reference it as shown in the examples, documentation, as well the example how to debug. Does it mean your question is "_How to find out the name fro a credential of type `Github Personal Access Token` within the Ansible Tower Environment (env) as that name is not referenced in documentation?_" – U880D Jun 16 '23 at 10:08
  • @U880D The question is How to access this credential in the playbook? There is an exclusive syntax for accessing every credential type (I provided one example for Type AWS in question). No I want the syntax for type "Github -Personal Access Token". The examples you provided are talking about the other credential types such as `Network` , `Machine`. – vishal Jun 16 '23 at 10:11
  • @U880D " just reference it as shown in the examples," Yeah definitely the only problem here is, there is no example in the official link. That is what I outlined in my question itself. if you are able to find, then please post that as an answer. that is exactly what I need. – vishal Jun 16 '23 at 10:13

1 Answers1

0

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.

U880D
  • 8,601
  • 6
  • 24
  • 40