Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a git_repo role #1580

Merged
merged 1 commit into from
Mar 13, 2024
Merged

Add a git_repo role #1580

merged 1 commit into from
Mar 13, 2024

Conversation

wbclark
Copy link
Contributor

@wbclark wbclark commented Sep 9, 2022

This role uses a single ansible data structure to manage a set of git repositories with potentially multiple remotes and multiple branches per remote.

@wbclark wbclark marked this pull request as draft September 9, 2022 14:43
@wbclark
Copy link
Contributor Author

wbclark commented Sep 9, 2022

Not yet properly tested, due to difficulty getting #1579 to play nicely with 5683c94

@wbclark wbclark force-pushed the git_repo_role branch 3 times, most recently from 497028d to c645070 Compare January 22, 2024 18:03
@wbclark wbclark marked this pull request as ready for review January 22, 2024 18:03
@wbclark
Copy link
Contributor Author

wbclark commented Jan 22, 2024

I added a README for this role explaining how it is used, and marked it ready for review

@ianballou
Copy link
Contributor

I haven't tested this entire thing, but it has been in use with our hotfixing process for over a year now and has been working well.

@wbclark
Copy link
Contributor Author

wbclark commented Feb 26, 2024

@evgeni @ehelms this is a basic role that we've been making wide use of in our hotfix building process. I've been using it also in my devel box, and generally anywhere that I need to set up some repositories with multiple remotes and branches and optionally do a basic bundle install or pip install (for repositories like tool belt, rpm packaging, pulpcore packaging, etc). It provides a simple interface that makes this all this very easy to manage and maintain in yaml (like updating the tracked release branches for various repositories being hotfixed).

Do you have some time this week to take a look?

@wbclark
Copy link
Contributor Author

wbclark commented Feb 26, 2024

Changes I've force pushed at https://github.com/wbclark/forklift/tree/git_repo_role actually aren't reflected here. I may need to re-open the PR.

EDIT: Nevermind, it took several minutes but it did eventually update.

@wbclark wbclark force-pushed the git_repo_role branch 2 times, most recently from 565abe6 to 2f87781 Compare February 26, 2024 19:05
@@ -0,0 +1,5 @@
---
- name: "Create local repository branch tracking specified remote branch"
ansible.builtin.command:
Copy link
Contributor Author

@wbclark wbclark Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to use the git_config module for this sort of thing, which was suggested by the maintainers of the git module as that module doesn't support everything that we need to do here, but branch creation was the one area where I could never make git_config work.

Doing it with the command module smells somewhat hacky, but it's not only worked very reliably, it also ends up being quite a bit simpler.

Copy link
Contributor

@ianballou ianballou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good to me! How I tested:

[ian@manicotto forklift]$ cat playbooks/repositories_test.yml
---
- hosts: all
  tasks:
    - name: "Setup git repositories"
      ansible.builtin.include_role:
        name: git_repo
      loop: "{{ git_repositories }}"
      loop_control:
        loop_var: repo
      vars:
        git_repo_repository: "{{ repo }}"
  fedora39:
    box_name: 'fedora/39-cloud-base'
    pty: true
    ansible:
      playbook: 'playbooks/repositories_test.yml'
      variables:
        git_repositories:
          - name: 'foreman'
            dir: '/home/vagrant'
            remotes:
              - name: 'origin'
                url: 'https://github.com/theforeman/foreman.git'
                branches:
                  - 'develop'
          - name: 'katello'
            dir: '/home/vagrant'
            remotes:
              - name: 'origin'
                url: 'https://github.com/Katello/katello.git'
                branches:
                  - 'master'
            python_packages:
              - 'ansible'
              - 'obal'
              - 'tito'

Only snag I hit was that git wasn't on my box. Should a role be responsible for ensuring certain dependencies are installed? I'm not sure if that's a usual Ansible expectation.

@ianballou
Copy link
Contributor

(For future reference, I took that playbook from here: wbclark@bb6de0d)

This role accepts a single complex data structure to
clone a git repository with multiple remotes and branches.
@wbclark
Copy link
Contributor Author

wbclark commented Mar 12, 2024

Only snag I hit was that git wasn't on my box. Should a role be responsible for ensuring certain dependencies are installed? I'm not sure if that's a usual Ansible expectation.

Good idea. I've added meta/main.yml with a dependency for the existing git role.

Copy link
Contributor

@ianballou ianballou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! In the future we can revamp the git role to use the generic package action so that other distros are supported.

Copy link
Member

@evgeni evgeni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said on Matrix: I think it's too complicated, but I don't mind having it if it's useful for y'all

Mergin.

@evgeni evgeni merged commit e060947 into theforeman:master Mar 13, 2024
8 checks passed
@wbclark wbclark deleted the git_repo_role branch March 13, 2024 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants