Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

geerlingguy commented Feb 28, 2020

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

geerlingguy commented Feb 28, 2020

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