Use ansible-collection from Github private repository

Bryant Tseng
1 min readAug 21, 2021

Environments

  • python 3.9.5
  • ansible 4.4.0

Prepare repository

Collection

I create a repository named: btsg.my_ansible_collection.

Which has one role called print_hello_message

This is the repository stands for our collection.

Inside the print_hello_message is a simple task that would print the message.

We can then use this role in other playbook

script and playbook

This is the repo named my_ansible_script.

Which contains a playbook called message.yml and a role named print_message

Playbook

print_message

Also inside this repo, there’s a file named requirements.yml. This is the file that contains the collection information which will be used to install the collection.

Inside this file we put the information of our collection repo located in github.

requirements.yml

Install collection

install collection

ansible-galaxy collection install -r requirements.yml

check installed collection

ansible-galaxy collection list

You can see a collection installed under ~/.ansible/collection/ansible_collections

Run playbook

After installing the collection, we can now run the playbook that uses the collection’s role

As the result, we can see that the playbook uses the imported role from the collection.

--

--