4
votes

I have a git project with few roles in the playbook, I want to use one of the roles in ansible galaxy.

The clone of the repo is working but it fails in the stage of archive it:

executing: git clone https://[email protected]/my-project/search-mysql search-mysql  executing: git archive --prefix=search-mysql/ --output=/tmp/tmp3f6ySq.tar search  
command git archive --prefix=search-mysql/ --output=/tmp/tmp3f6ySq.tar search failed

Using requirements.yml file, and

ansible-galaxy install --role-file=requirements.yml --roles-path=roles --force

any idea why the archive is failing? can I only download the role and not the entire project(search-mysql)?

Thanks,

2
Can you show the related part of your requirements.yml? I've never seen a feature how to use a single subdirectory of a repo as the source for galaxy roles. Curious how you tried this.udondan
sure, but this is only in testing, I am still cant get it to work: - src: [email protected]/my-project/search-mysql version: master name: search-mysql this will clone all my project, I need either to clone only the role folders or call a specific role in this project from my ansible.A1001

2 Answers

3
votes

Ansible Galaxy now has support for Collections. Collections may contain multiple roles.


Old answer:

Unless there is an undocumented feature (which is not the rarest thing to happen) a dedicated git repo is required for a galaxy compatible role. If a role is a component used by different projects, as it seems in your case, it anyway makes sense to store it in a separate project. Can't you move the role out and reference it in both projects?

A hacky workaround might be this:

In your requirements file specify a location where your roles repo will be saved to:

- src: [email protected]/my-project/search-mysql
  version: master
  name: search-mysql
  path: ./role_collection

Now ansible-galaxy will save the repo in ./role_collection/search-mysql

This is just to not pollute the original roles directory with a folder which actually holds a collection of roles.

In your playbook you can also specify a full path for every role:

- hosts: ...
  roles:
    - ./role_collection/search-mysql/path/to/your/role/inside/the/repo
0
votes

This came from ansible galaxy support: "I just checked and this is a one role per repo situation. If you want to grab individual roles from the repository, then you'll need to split them off."