`ansible-builder` ERROR when scm/git sourced content is in `requirements.yml`

Post

I am having some trouble trying to utilize a local/custom(non-galaxy) collection with ansible-builder. I’ve had no problem using ansible-builder until I started looking at packing in some newer collections we’ve developed internally.

The following requirements file is what I am currently trying to use. There are examples of https and git(ssh) methods for installing the collection in question. This requirements file has no problem working on the ansible-galaxy command line via ansible-galaxy install -r requirements.yaml or ansible-galaxy collection install -r requirements.yaml

My requirements.yaml file

---
roles:
collections:
  - ansible.posix
  - ansible.utils
  - community.general
  - community.docker
  - community.network
  # This works with ansible galaxy 
  #- name: git@gitlab.flyingtoaster.dev:ansible_collections/flyingtoaster.docker.git
  #  type: git
  #  version: develop
  # This works with ansible galaxy 
  - name: https://gitlab.flyingtoaster.dev/ansible_collections/flyingtoaster.docker.git
    type: git
    version: develop
...

ansible-builder build command output:

Running command:
  docker build -f context/Dockerfile -t toast/flyingtoaster-ee context
...showing last 20 lines of output...
#17 [galaxy 5/5] RUN ANSIBLE_GALAXY_DISABLE_GPG_VERIFY=1 ansible-galaxy collection install --pre -r requirements.yml --collections-path "/usr/share/ansible/collections"
#17 12.36 ERROR! Could not find git executable to extract the collection from the Git repository `https://gitlab.flyingtoaster.dev/ansible_collections/flyingtoaster.docker.git`.
#17 12.36 Starting galaxy collection install process
#17 12.36 Process install dependency map
#17 ERROR: process "/bin/sh -c ANSIBLE_GALAXY_DISABLE_GPG_VERIFY=1 ansible-galaxy collection install $ANSIBLE_GALAXY_CLI_COLLECTION_OPTS -r requirements.yml --collections-path \"/usr/share/ansible/collections\"" did not complete successfully: exit code: 1
------
 > [galaxy 5/5] RUN ANSIBLE_GALAXY_DISABLE_GPG_VERIFY=1 ansible-galaxy collection install --pre -r requirements.yml --collections-path "/usr/share/ansible/collections":
12.36 ERROR! Could not find git executable to extract the collection from the Git repository `https://gitlab.flyingtoaster.dev/ansible_collections/flyingtoaster.docker.git`.
12.36 Starting galaxy collection install process
12.36 Process install dependency map
------
Dockerfile:43
--------------------
  41 |
  42 |     RUN ansible-galaxy role install $ANSIBLE_GALAXY_CLI_ROLE_OPTS -r requirements.yml --roles-path "/usr/share/ansible/roles"
  43 | >>> RUN ANSIBLE_GALAXY_DISABLE_GPG_VERIFY=1 ansible-galaxy collection install $ANSIBLE_GALAXY_CLI_COLLECTION_OPTS -r requirements.yml --collections-path "/usr/share/ansible/collections"
  44 |
  45 |     # Builder build stage
--------------------
ERROR: failed to solve: process "/bin/sh -c ANSIBLE_GALAXY_DISABLE_GPG_VERIFY=1 ansible-galaxy collection install $ANSIBLE_GALAXY_CLI_COLLECTION_OPTS -r requirements.yml --collections-path \"/usr/share/ansible/collections\"" did not complete successfully: exit code: 1

An error occurred (rc=1), see output line(s) above for details.

I’ve struggled to find any documentation around using custom scm/git repos in the requirements file specifically for ansible-builder. However seeing as this works just fine with the ansible-galaxy command line as documented, I struggle to understand where the hangup is. Also to be clear, the ansible-builder command works as expected without any error when the internal git/scm item is removed from/commented out in the requirements file.

I greatly appreciate any assistance or pointing in the right direction that anyone can provide.

Thank you!

1 Like

Hi, I think this error message is the answer.

12.36 ERROR! Could not find git executable to extract the collection from the Git repository `https://gitlab.flyingtoaster.dev/ansible_collections/flyingtoaster.docker.git`.

I mean, the image you’ve specified as base_image does not contain git command.

As a quick workaround, append additional_build_steps to your execution-environment.yml file. This installs git-core just before ansible-galaxy command invokation.

additional_build_steps:
  prepend_galaxy:
    - RUN $PKGMGR install git-core -y; if [ -z $PKGMGR_PRESERVE_CACHE ]; then $PKGMGR clean all; fi

Note that Ansible Builder has ability to install system packages using bindep through dependencies.system in execution-environment.yml and git-core can be installed via bindep, but bindep will be invoked AFTER ansible-galaxy, so in your case bindep can not help you.

Hope this helps.

4 Likes

Thank you, thank you, THANK YOU!

I can’t tell you how many cycles I wasted on that error. A clear problem of tunnel vision/spending too much time on a problem and needing a fresh set of eyes. You’re absolutely correct my problem was in fact the lack of a git executable in the image itself and not the git repo.

I’m most thankful for your suggested additions to my build file, you certainly pointed me in the right direction.

I know I’m a random person on the internet, but you really made a difference with whatever time and energy you put into this reply, so again, thank you!

5 Likes

I’m glad it seems to be solved, it is unusual to receive such a polite and heartwarming reply, thank you :blush:

In fact, for the users who have faced some problems, the first step to getting enough answers from the community is providing enough information. However it is not easy to organize the situation and describe it clearly to others.
In this sense, I was able to help you because YOU definitely provided enough information for us to understand your situation clearly and correctly.
That is, the goals you want to achieve, the problems you faced, your thought, the tries you made and its results, the actual files and the actual logs.

This topic you have created will help someone else in the future who has faced the same problem. So I would also want to say thank you for your great job and contribution!

5 Likes