community.general.github_app_access_token lookup – Obtain short-lived Github App Access tokens

Note

This lookup plugin is part of the community.general collection (version 14.0.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general. You need further requirements to be able to use this lookup plugin, see Requirements for details.

To use it in a playbook, specify: community.general.github_app_access_token.

New in community.general 8.2.0

Synopsis

  • This generates a Github access token that can be used with a git command, if you use a Github App.

Requirements

The below requirements are needed on the local controller node that executes this lookup.

Keyword parameters

This describes keyword parameters of the lookup. These are the values key1=value1, key2=value2 and so on in the following examples: lookup('community.general.github_app_access_token', key1=value1, key2=value2, ...) and query('community.general.github_app_access_token', key1=value1, key2=value2, ...)

Parameter

Comments

app_id

aliases: client_id

string / required

Your GitHub App’s client ID or GitHub App ID. You can find these in the Settings page.

GitHub recommends using the client ID instead of the numeric app ID (see https://github.blog/changelog/2024-08-23-client-ids-are-now-included-in-app-api-responses/).

The client_id alias has been added in community.general 13.5.0.

github_url

string

added in community.general 11.4.0

Base URL for the GitHub API (for GitHub Enterprise Server).

Example: https://github-enterprise-server.example.com/api/v3

Default: "https://api.github.com"

installation_id

string / required

The installation ID that contains the git repository you would like access to.

As of 2023-12-24, this can be found at Settings page > Integrations > Application. The last part of the URL in the configure button is the installation ID.

Alternatively, you can use PyGithub (https://github.com/PyGithub/PyGithub) to get your installation ID.

key_path

path

Path to your private key.

Either key_path or private_key must be specified.

private_key

string

added in community.general 10.0.0

GitHub App private key in PEM file format as string.

Either key_path or private_key must be specified.

token_expiry

integer

How long the token should last for in seconds.

Default: 600

Examples

- name: Get access token to be used for git checkout with app_id=123456, installation_id=64209
  ansible.builtin.git:
    repo: >-
      https://x-access-token:{{ github_token }}@github.com/hidden_user/super-secret-repo.git
    dest: /srv/checkout
  vars:
    github_token: >-
      {{ lookup('community.general.github_app_access_token', key_path='/home/to_your/key',
                app_id='123456', installation_id='64209') }}

- name: Get access token using the GitHub App's client ID instead of its numeric app ID
  ansible.builtin.git:
    repo: >-
      https://x-access-token:{{ github_token }}@github.com/hidden_user/super-secret-repo.git
    dest: /srv/checkout
  vars:
    github_token: >-
      {{ lookup('community.general.github_app_access_token', key_path='/home/to_your/key',
                client_id='Iv1.a1b2c3d4e5f6g7h8', installation_id='64209') }}

Return Value

Key

Description

Return value

list / elements=string

A one-element list containing your GitHub access token.

Note on ansible-core 2.22+, the token will be registered as a secret. See Masking secrets in Ansible output for more information.

Returned: success

Authors

  • Poh Wei Sheng (@weisheng-p)

  • Bruno Lavoie (@blavoie)