gotmax23.github_cli
Ansible Role: github_cli
Ansible role for installing the GitHub CLI (gh).
Beta Warning
This role is in beta and should not be used in production. There may be breaking changes between releases, so read the release notes before using.
Requirements
This role needs other collections that are not included in Ansible's core package.
To install the required collections, create a requirements.yml
file with these lines:
---
collections:
- community.general
If you are using Ansible version 2.10 or later, run this command:
ansible-galaxy install -r requirements.yml
If you are using Ansible 2.9, run this command instead:
ansible-galaxy collection install -r requirements.yml
Role Variables
Installation Methods
You can choose how to install the GitHub CLI. You can change the default install method by setting github_cli_install_method
to one of the options below.
github_cli_install_method=repo
Description: Installs GitHub CLI from the official Apt and RPM repositories.
Supported Distributions: This method works with all Debian-based systems and RPM-based systems like Fedora, CentOS, Almalinux, Rocky Linux, RHEL, OpenSUSE Leap, and Tumbleweed.
Default: Yes (for all distributions except Archlinux, where this option is not supported.)
github_cli_install_method=distro_package
Description: Installs GitHub CLI from your system's package manager, if available.
Supported Distributions: Archlinux, OpenSUSE Tumbleweed, and Fedora.
Default: Only for Archlinux where github_cli_install_method=repo
is not supported.
Here are the role's variables and their default values, found in [defaults/main.yml
]. You can change these to customize how the role behaves.
---
# defaults file for github_cli
# Options:
# - `present` makes sure GitHub CLI is installed
# - `absent` makes sure GitHub CLI is not installed.
# To change installation methods, run this role with the old setting using `state=absent`,
# then run it again with the new setting using `state=present`.
github_cli_state: present
# Default installation method based on your distribution.
_github_cli_install_method:
Archlinux: distro_package # Default for Archlinux
default: repo # Default for all other distros
# You can override this variable, but make sure the option you choose supports your distribution.
github_cli_install_method: "{{ _github_cli_install_method[ansible_distribution] | default(_github_cli_install_method['default']) }}"
# Check the RPM repository key's fingerprint before importing it.
# This is only available for the RPM repo.
github_cli_check_rpm_key_fingerprint: true
# Default is based on GitHub's recommendation.
github_cli_apt_repo_codename: stable
# On Yum/Dnf: allows `enablerepo` to be passed to the package module.
github_cli_enablerepo: omit
Example Playbook
---
- name: Install GitHub CLI
hosts: all
become: true
tasks:
- name: Update apt cache
when: ansible_pkg_mgr == "apt"
ansible.builtin.apt:
update_cache: true
cache_valid_time: 3600
- name: Install GitHub CLI
ansible.builtin.include_role:
name: "gotmax23.github_cli"
Compatibility
This role has been tested with the latest version of Ansible core and collections from Ansible Galaxy. It only officially supports the latest version of Ansible but will provide best effort support for others.
This role works with the following distributions:
Distro | Versions |
---|---|
Archlinux | any |
Debian | buster, bullseye, bookworm |
EL | 8 |
Fedora | 34, 35, 36 |
OpenSUSE | 15.3, tumbleweed |
Ubuntu | bionic, focal |
License
[MIT License]
Author
Maxwell G (@gotmax23)
[Links to badges and source code are included in original text]
Ansible role that installs Github CLI (gh).
ansible-galaxy install gotmax23.github_cli