semaphore icon indicating copy to clipboard operation
semaphore copied to clipboard

Roles requirements.yml directory and repository structure

Open jeffreznik opened this issue 1 year ago • 10 comments

Hi there, relatively new to Semaphore and Ansible in general. My git repository contains code other than Ansible playbooks, and is structured so that all Ansible related files are in an ansible subdirectory in the root of the project:

Repository structure:
/ (root)
├── ansible/
│   ├── group_vars/
│   │   ├── ...
│   ├── playbooks/
│   │   ├── initialize.yml
│   ├── roles/
│   │   ├── requirements.yml
├── module2/
│   ├── ...
├── module3/
│   ├── ...

So in Semaphore I create Task Templates pointing to my playbook files like this: ansible/playbooks/initialize.yml

My playbook has role requirements listed in ansible/roles/requirements.yml. Problem is Semaphore assumes the roles folder is in the root of the project. Is there a way to change this behavior? What is the recommended approach for installing roles if your project does not conform to normal convention? It would be nice if Semaphore looked "one directory up" from your playbook file location for the roles directory (which would not break existing convention), or if you could specify a subdirectory in your repo where Ansible-related files are located.

I am running Semaphore via Docker (latest version: 2.9.4).

jeffreznik avatar Nov 04 '23 15:11 jeffreznik

For now I've just symlinked /ansible/roles/ to /roles/ and it seems to be working. Would still be nice to have a cleaner approach to this.

jeffreznik avatar Nov 04 '23 16:11 jeffreznik

Me too. In my environment semaphore is expecting the roles folder in "/playbooks/roles", but i stored them into "/roles"...

Frickeldave avatar Nov 06 '23 13:11 Frickeldave

add a "ansible.cfg" in the root of your repository and add these lines

[defaults]
roles_path = roles:/tmp/semaphore/.ansible/roles:/usr/share/ansible/roles
collections_paths = collections:/tmp/semaphore/.ansible/collections:/usr/share/ansible/collections

I am also quite new to this, but I read the docu and came up with a template for a new ansible repository, so that i don't have to think about every time: https://github.com/betadots/ansible-control-repo-template

rwaffen avatar Nov 07 '23 09:11 rwaffen

roles_path is where ansible should look for installed roles. What I'm trying to do is tell Semaphore where my requirements.yml file is so it can install them. Normally you need to call ansible-galaxy before running a playbook but Semaphore does this for you.

jeffreznik avatar Nov 09 '23 05:11 jeffreznik

when i do it like this, it searches also for requirements.yml there and installs any role from it.

rwaffen avatar Nov 09 '23 14:11 rwaffen

You have roles/requirements.yml in your project root, my initial question was how do you tell Semaphore to see it when it's not?

jeffreznik avatar Nov 10 '23 02:11 jeffreznik

hmm okay, i see your point. i thought this is more a ansible then a semaphore thing. and by telling ansible where my roles are, it should find the yaml. but I didn't test it.

rwaffen avatar Nov 10 '23 08:11 rwaffen

@jeffreznik Did you find another solution besides symlinking /ansible/roles/ to /roles/? I have the exact same project setup and I am facing the exact same issue.

riker09 avatar Feb 07 '24 08:02 riker09

No, unfortunately this is still the only solution that worked for me.

On Wed, Feb 7, 2024, 2:22 a.m. Volker Thiel @.***> wrote:

@jeffreznik https://github.com/jeffreznik Did you find another solution besides symlinking /ansible/roles/ to /roles/? I have the exact same project setup and I am facing the exact same issue.

— Reply to this email directly, view it on GitHub https://github.com/ansible-semaphore/semaphore/issues/1609#issuecomment-1931509179, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAVCQGIQX5MG65H6QCULYT3YSM2VHAVCNFSM6AAAAAA65UVRQGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZRGUYDSMJXHE . You are receiving this because you were mentioned.Message ID: @.***>

jeffreznik avatar Feb 07 '24 13:02 jeffreznik

I think there is an open pull request which sets the role path relative to the playbook.

tboerger avatar Feb 07 '24 18:02 tboerger

can anyone point me to why i have collections/requirements.yml and roles/requirements.yml in the ROOT of my repo and still sephamore wont detect it at all? has anyone got an example of what the file should look like?

Renderer6060 avatar Feb 29 '24 09:02 Renderer6060