DEV Community

Ari Kalfus
Ari Kalfus

Posted on

Automatically Deploy Your Ansible Galaxy Collections

From a comment on the announcement article:

For this contest, you'll only be able to submit projects that you started after this announcement post was published.

Well, I guess I am disqualified. But, leaving this post up as a resource for anyone that may like it.

My Workflow

Ansible Galaxy Collections were released in late 2019 as a modern method of sharing Ansible roles, plugins, and other snippets of a playbook. Deploying a Collection involves several ansible-galaxy collection commands.

I created a GitHub Action to simplify the process of publishing and updating a Collection to Ansible Galaxy.

The custom Action also provides some conveniences, such as allowing the Action workflow to assign a version to the Galaxy Collection.

For example:

- name: Get the version from the tag
  run: echo ::set-env name=RELEASE_VERSION::${GITHUB_REF/refs\/tags\//

- name: Injecting a dynamic Collection version
  uses: artis3n/ansible_galaxy_collection@v2
  with:
    api_key: '${{ secrets.GALAXY_API_KEY }}'
    galaxy_version: '${{ env.RELEASE_VERSION }}'
Enter fullscreen mode Exit fullscreen mode

Submission Category:

DIY Deployments

Yaml File or Link to Code

I use this in a small personal collection:

https://github.com/artis3n/ansible-collection-github/blob/master/.github/workflows/deploy.yml#L14

Such a simple workflow, so convenient!

The full Action code (Typescript published into a Docker-based GitHub Action) is here:

GitHub logo artis3n / ansible_galaxy_collection

Deploy a Collection to Ansible Galaxy.

ansible_galaxy_collection

GitHub Workflow Status GitHub release (latest SemVer) GitHub last commit Maintainability GitHub GitHub followers Twitter Follow

Deploy a Collection to Ansible Galaxy.

Requirements

This action expects to be run from a repository with certain met conditions.

  1. The repository contains a valid Ansible Galaxy Collection, meaning it minimally contains a galaxy.yml file and a README.md.

An example workflow using this action can be found here and in the tests.

Inputs

api_key

Required: Ansible Galaxy API key.

This should be stored in a Secret on GitHub. See Creating and Using Secrets Encrypted Variables.

collection_dir

Default: ./

The directory in which the Ansible Collection is stored. This defaults to the project root.

Only change this if your Collection is not stored in your project root.

galaxy_version

Semver-compatible string: 1, 1.1, 1.1.1, 1.1.1-alpha

Dynamically inject a semver-compatible version into your galaxy.yml file.

galaxy_config_file (Deprecated)

Default: galaxy.yml

A collection must have a galaxy.yml file that contains the necessary information to build…

Additional Resources / Info

I wrote about how I created this action and some of the philosophy behind GitHub Actions here:

Oldest comments (0)