community.general.github_key (8.5.0) — module

Manage GitHub access keys

Authors: Robert Estelle (@erydo)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Creates, removes, or updates GitHub access keys.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Read SSH public key to authorize
  ansible.builtin.shell: cat /home/foo/.ssh/id_rsa.pub
  register: ssh_pub_key
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Authorize key with GitHub
  local_action:
    module: github_key
    name: Access Key for Some Machine
    token: '{{ github_access_token }}'
    pubkey: '{{ ssh_pub_key.stdout }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Alternatively, a single task can be used reading a key from a file on the controller
- name: Authorize key with GitHub
  community.general.github_key:
    name: Access Key for Some Machine
    token: '{{ github_access_token }}'
    pubkey: "{{ lookup('ansible.builtin.file', '/home/foo/.ssh/id_rsa.pub') }}"

Inputs

    
name:
    description:
    - SSH key name
    required: true
    type: str

force:
    default: true
    description:
    - The default is V(true), which will replace the existing remote key if it is different
      than O(pubkey). If V(false), the key will only be set if no key with the given O(name)
      exists.
    type: bool

state:
    choices:
    - present
    - absent
    default: present
    description:
    - Whether to remove a key, ensure that it exists, or update its value.
    type: str

token:
    description:
    - GitHub Access Token with permission to list and create public keys.
    required: true
    type: str

pubkey:
    description:
    - SSH public key value. Required when O(state=present).
    type: str

Outputs

deleted_keys:
  description: An array of key objects that were deleted. Only present on state=absent
  returned: When state=absent
  sample:
  - created_at: YYYY-MM-DDTHH:MM:SZ
    id: 0
    key: BASE64 encoded key
    read_only: false
    url: http://example.com/github key
  type: list
key:
  description: Metadata about the key just created. Only present on state=present
  returned: success
  sample:
    created_at: YYYY-MM-DDTHH:MM:SZ
    id: 0
    key: BASE64 encoded key
    read_only: false
    url: http://example.com/github key
  type: dict
matching_keys:
  description: An array of keys matching the specified name. Only present on state=present
  returned: When state=present
  sample:
  - created_at: YYYY-MM-DDTHH:MM:SZ
    id: 0
    key: BASE64 encoded key
    read_only: false
    url: http://example.com/github key
  type: list