Skip to content

Instantly share code, notes, and snippets.

@geerlingguy
Created February 28, 2020 17:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geerlingguy/fba1809a649acf462b69b3687da8930b to your computer and use it in GitHub Desktop.
Save geerlingguy/fba1809a649acf462b69b3687da8930b to your computer and use it in GitHub Desktop.
Playbook that builds and publishes a collection to Ansible Galaxy
---
- hosts: localhost
connection: local
gather_facts: false
vars:
# This should be set via the command line at runtime.
tag: ''
pre_tasks:
- name: Ensure the ANSIBLE_GALAXY_TOKEN environment variable is set.
fail:
msg: ANSIBLE_GALAXY_TOKEN is not set.
when: "lookup('env','ANSIBLE_GALAXY_TOKEN') == ''"
- name: Ensure the ~/.ansible directory exists.
file:
path: ~/.ansible
state: directory
- name: Write the Galaxy token to ~/.ansible/galaxy_token
copy:
content: |
token: {{ lookup('env','ANSIBLE_GALAXY_TOKEN') }}
dest: ~/.ansible/galaxy_token
tasks:
- name: Template out the galaxy.yml file.
template:
src: templates/galaxy.yml.j2
dest: ../galaxy.yml
- name: Build the collection.
command: >
ansible-galaxy collection build
chdir=../
- name: Publish the collection.
command: >
ansible-galaxy collection publish ./geerlingguy-php_roles-{{ tag }}.tar.gz
chdir=../
@geerlingguy
Copy link
Author

In my .travis.yml file:

deploy:
  provider: script
  script: ansible-playbook -i 'localhost,' scripts/deploy.yml -e "tag=$TRAVIS_TAG"
  'on':
    tags: true

@geerlingguy
Copy link
Author

Also an explanation with more background, in blog post form: Automatically building and publishing Ansible Galaxy Collections

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment