Ansible

How to integrate Ansible with Cloudsmith

Ansible is open-source software for provisioning, configuration management, and application deployment.

In the following examples:

IdentifierDescription
OWNERYour Cloudsmith organisation name (namespace)
REPOSITORYYour Cloudsmith Repository identifier (also called "slug")
DISTROYour distribution (i.e el, fedora, debian etc)
VERSIONYour version name (i.e 7, 29, hardy, buster etc)
FINGERPRINTThe 8 Byte fingerprint of the Public GPG key for the repository
TOKENYour Cloudsmith Entitlement Token (see Entitlements for more details)
USERNAMEYour Cloudsmith username
PASSWORDYour Cloudsmith password
API-KEYYour Cloudsmith API Key

Adding a RPM repository

To add a Cloudsmith repository for RPM packages using Ansible, you would use the Ansible yum_repository module. The yum_repository module can add or remove YUM repositories in RPM-based Linux distributions.

Example yum_repository task:

Public Repository

- name: Add Cloudsmith Repository
  yum_repository:
    name: cloudsmith
    description: Cloudsmith
    file: cloudsmith
    baseurl: https://dl.cloudsmith.io/public/OWNER/REPOSITORY/rpm/DISTRO/VERSION/$basearch
    repo_gpgcheck: yes
    gpgkey: https://dl.cloudsmith.io/public/OWNER/REPOSITORY/cfg/gpg/gpg.FINGERPRINT.key
    enabled: yes
  become: true

Private Repository

- name: Add Cloudsmith Repository
  yum_repository:
    name: cloudsmith
    description: Cloudsmith
    file: cloudsmith
    baseurl: https://dl.cloudsmith.io/TOKEN/OWNER/REPOSITORY/rpm/DISTRO/VERSION/$basearch
    repo_gpgcheck: yes
    gpgkey: https://dl.cloudsmith.io/TOKEN/OWNER/REPOSITORY/cfg/gpg/gpg.FINGERPRINT.key
    enabled: yes 
  become: true
- name: Add Cloudsmith Repository
  yum_repository:
    name: cloudsmith
    description: Cloudsmith
    file: cloudsmith
    baseurl: https://dl.cloudsmith.io/basic/OWNER/REPOSITORY/rpm/DISTRO/VERSION/$basearch
    repo_gpgcheck: yes
    gpgkey: https://dl.cloudsmith.io/basic/OWNER/REPOSITORY/cfg/gpg/gpg.FINGERPRINT.key
    username: USERNAME
    password: PASSWORD
    enabled: yes
  become: true
- name: Add Cloudsmith Repository
  yum_repository:
    name: cloudsmith
    description: Cloudsmith
    file: cloudsmith
    baseurl: https://dl.cloudsmith.io/basic/OWNER/REPOSITORY/rpm/DISTRO/VERSION/$basearch
    repo_gpgcheck: yes
    gpgkey: https://dl.cloudsmith.io/basic/OWNER/REPOSITORY/cfg/gpg/gpg.FINGERPRINT.key
    username: USERNAME
    password: API-KEY
    enabled: yes
  become: true
- name: Add Cloudsmith Repository
  yum_repository:
    name: cloudsmith
    description: Cloudsmith
    file: cloudsmith
    baseurl: https://dl.cloudsmith.io/basic/OWNER/REPOSITORY/rpm/DISTRO/VERSION/$basearch
    repo_gpgcheck: yes
    gpgkey: https://dl.cloudsmith.io/basic/OWNER/REPOSITORY/cfg/gpg/gpg.FINGERPRINT.key
    username: token
    password: TOKEN
    enabled: yes
  become: true

Install a package

To install a RPM package via Ansible, you use the Ansible yum module:

- name: Install a package
  yum:
    name: PACKAGE_NAME
    state: present
    update_cache: yes
  become: true

Adding a Debian repository

To add a Cloudsmith repository for Debian packages using Ansible, you would use the Ansible apt_key module and the apt_repository module.

Example apt_key and apt_repository tasks:

Public Repository

- name: Import Cloudsmith Repository GPG key
  apt_key:
    url: https://dl.cloudsmith.io/public/OWNER/REPOSITORY/cfg/gpg/gpg.FINGERPRINT.key
    state: present
  become: true

- name: Add Cloudsmith Repository
  apt_repository:
    repo: deb https://dl.cloudsmith.io/public/OWNER/REPOSITORY/deb/DISTRO VERSION main
    state: present
  become: true

Private Repository

- name: Import Cloudsmith Repository GPG key
  apt_key:
    url: https://dl.cloudsmith.io/TOKEN/OWNER/REPOSITORY/cfg/gpg/gpg.FINGERPRINT.key
    state: present
  become: true

- name: Add Cloudsmith Repository
  apt_repository:
    repo: deb https://dl.cloudsmith.io/TOKEN/OWNER/REPOSITORY/deb/DISTRO VERSION main
    state: present
  become: true
- name: Import Cloudsmith Repository GPG key
  apt_key:
    url: https://USERNAME:[email protected]/basic/OWNER/REPOSITORY/cfg/gpg/gpg.FINGERPRINT.key
    state: present
  become: true

- name: Add Cloudsmith Repository
  apt_repository:
    repo: deb https://USERNAME:[email protected]/basic/OWNER/REPOSITORY/deb/DISTRO VERSION main
    state: present
  become: true
- name: Import Cloudsmith Repository GPG key
  apt_key:
    url: https://USERNAME:[email protected]/basic/OWNER/REPOSITORY/cfg/gpg/gpg.FINGERPRINT.key
    state: present
  become: true

- name: Add Cloudsmith Repository
  apt_repository:
    repo: deb https://USERNAME:[email protected]/basic/OWNER/REPOSITORY/deb/DISTRO VERSION main
    state: present
  become: true
- name: Import Cloudsmith Repository GPG key
  apt_key:
    url: https://token:[email protected]/basic/OWNER/REPOSITORY/cfg/gpg/gpg.FINGERPRINT.key
    state: present
  become: true

- name: Add Cloudsmith Repository
  apt_repository:
    repo: deb https://token:[email protected]/basic/OWNER/REPOSITORY/deb/DISTRO VERSION main
    state: present
  become: true

Install a package

To install a Debian package via Ansible, you use the Ansible apt module:

- name: Install a package
  apt:
    name: PACKAGE_NAME
    state: present
    update_cache: yes
  become: true

Cloudsmith is the new standard in Package / Artifact Management and Software Distribution

With support for all major package formats, you can trust us to manage your software supply chain.


Start My Free Trial Now
Cookie Declaration (Manage Cookies)