Playbook that builds and publishes a collection to Ansible Galaxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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=../ |
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
In my
.travis.yml
file: