community / community.general / 0.1.1 / module / github_deploy_key Manages deploy keys for GitHub repositories. Authors: Ali (@bincyber) preview | supported by communitycommunity.general.github_deploy_key (0.1.1) — module
Install with ansible-galaxy collection install community.general:==0.1.1
collections: - name: community.general version: 0.1.1
Adds or removes deploy keys for GitHub repositories. Supports authentication using username and password, username and password and 2-factor authentication code (OTP), OAuth2 token, or personal access token. Admin rights on the repository are required.
# add a new read-only deploy key to a GitHub repository using basic authentication - github_deploy_key: owner: "johndoe" repo: "example" name: "new-deploy-key" key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAwXxn7kIMNWzcDfou..." read_only: yes username: "johndoe" password: "supersecretpassword"
# remove an existing deploy key from a GitHub repository - github_deploy_key: owner: "johndoe" repository: "example" name: "new-deploy-key" key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAwXxn7kIMNWzcDfou..." force: yes username: "johndoe" password: "supersecretpassword" state: absent
# add a new deploy key to a GitHub repository, replace an existing key, use an OAuth2 token to authenticate - github_deploy_key: owner: "johndoe" repository: "example" name: "new-deploy-key" key: "{{ lookup('file', '~/.ssh/github.pub') }}" force: yes token: "ABAQDAwXxn7kIMNWzcDfo..."
# re-add a deploy key to a GitHub repository but with a different name - github_deploy_key: owner: "johndoe" repository: "example" name: "replace-deploy-key" key: "{{ lookup('file', '~/.ssh/github.pub') }}" username: "johndoe" password: "supersecretpassword"
# add a new deploy key to a GitHub repository using 2FA - github_deploy_key: owner: "johndoe" repo: "example" name: "new-deploy-key-2" key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAwXxn7kIMNWzcDfou..." username: "johndoe" password: "supersecretpassword" otp: 123456
# add a read-only deploy key to a repository hosted on GitHub Enterprise - github_deploy_key: github_url: "https://api.example.com" owner: "janedoe" repo: "example" name: "new-deploy-key" key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAwXxn7kIMNWzcDfou..." read_only: yes username: "janedoe" password: "supersecretpassword"
key: description: - The SSH public key to add to the repository as a deploy key. required: true otp: aliases: - 2fa_token description: - The 6 digit One Time Password for 2-Factor Authentication. Required together with I(username) and I(password). name: aliases: - title - label description: - The name for the deploy key. required: true repo: aliases: - repository description: - The name of the GitHub repository. required: true force: default: 'no' description: - If C(true), forcefully adds the deploy key by deleting any existing deploy key with the same public key or title. type: bool owner: aliases: - account - organization description: - The name of the individual account or organization that owns the GitHub repository. required: true state: choices: - present - absent default: present description: - The state of the deploy key. token: description: - The OAuth2 token or personal access token to authenticate with. Mutually exclusive with I(password). password: description: - The password to authenticate with. Alternatively, a personal access token can be used instead of I(username) and I(password) combination. username: description: - The username to authenticate with. Should not be set when using personal access token read_only: default: 'yes' description: - If C(true), the deploy key will only be able to read repository contents. Otherwise, the deploy key will be able to read and write. type: bool github_url: default: https://api.github.com description: - The base URL of the GitHub API required: false type: str
error: description: the error message returned by the GitHub API returned: failed sample: key is already in use type: str http_status_code: description: the HTTP status code returned by the GitHub API returned: failed sample: 400 type: int id: description: the key identifier assigned by GitHub for the deploy key returned: changed sample: 24381901 type: int msg: description: the status message describing what occurred returned: always sample: Deploy key added successfully type: str