4

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://myuser@github.com/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,

udondan
  • 57,263
  • 20
  • 190
  • 175
A1001
  • 111
  • 2
  • 7
  • 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 Jun 23 '16 at 10:42
  • sure, but this is only in testing, I am still cant get it to work: - src: https://myuser@github.com/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 Jun 23 '16 at 10:54

2 Answers2

3

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: myuser@github.com/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
udondan
  • 57,263
  • 20
  • 190
  • 175
  • This is basically what I'm looking for, but trying this still generate the same error on the archive step: command git archive --prefix=search-mysql/ --output=/tmp/tmpnnxPoK.tar search failed – A1001 Jun 23 '16 at 11:40
  • Oh, I thought this worked for you. Try adding an `scm: git` to the requirements.yml entry – udondan Jun 23 '16 at 11:54
  • still no.... I think tha becuase I'm not working on master the archive is failing, i need an option to checkout to the working branch (-b) after the clone and when ansible will run the archive on - git archive --prefix=search/ --output=/tmp/tmpkMNgsG.tar search - where search is the new branch it will hopefully work. – A1001 Jun 23 '16 at 12:05
0

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."

A1001
  • 111
  • 2
  • 7