ansible-builder icon indicating copy to clipboard operation
ansible-builder copied to clipboard

ansible-builder and local collection

Open adn1107 opened this issue 3 years ago • 4 comments

trying requirements.yml with this content

- name: ibm.ims_command_operator
    version: 1.0.0
    source: '/Users/adn/workspaces/nazare/cp4z/ee/ee-for-ims/ims-command-operator/'
    type: dir

but ansible-buider build failed with:

#11 [galaxy 5/5] RUN ansible-galaxy collection install  -r requirements.yml --collections-path /usr/share/ansible/collections
#11 sha256:5ff3f1bddc3a927f45af6533c50575aadb53a90042fc94a9d0014169b707f8bd
#11 1.098 Starting galaxy collection install process
#11 1.099 Process install dependency map
#11 3.971 ERROR! Failed to find the collection dir deps: The collection galaxy.yml path '/Users/adn/workspaces/nazare/cp4z/ee/ee-for-ims/ims-command-operator/galaxy.yml' does not exist.
#11 ERROR: executor failed running [/bin/sh -c ansible-galaxy collection install $ANSIBLE_GALAXY_CLI_COLLECTION_OPTS -r requirements.yml --collections-path /usr/share/ansible/collections]: exit code: 1

but i do have '/Users/adn/workspaces/nazare/cp4z/ee/ee-for-ims/ims-command-operator/galaxy.yml'

(builder) (base) ➜  ims-command-operator ll /Users/adn/workspaces/nazare/cp4z/ee/ee-for-ims/ims-command-operator/
total 24
-rw-r--r--  1 adn  staff    31B May 11 18:16 README.md
-rw-r--r--  1 adn  staff   2.7K May 11 18:26 galaxy.yml
drwxr-xr-x  3 adn  staff    96B May 11 18:22 inventories
-rw-r--r--  1 adn  staff   1.1K May 11 18:26 operator-config.yml
drwxr-xr-x  4 adn  staff   128B May 11 18:24 playbooks
-rw-r--r--  1 adn  staff     0B May 11 18:29 requirements.txt

is it possible to specify a local collection instead of a collection hosted on galaxy.ansible.com?

adn1107 avatar May 12 '22 01:05 adn1107

The problem here is that builder is executed within a container at this point and that the collections path is not mounted into it. One option would be to add the collection path via a additional builder step. Would that be a solution for you?

eqrx avatar May 17 '22 13:05 eqrx

I'd be interested for a solution on this topic as well. Is there a way to copy a collection during the build step?

tepene avatar Jun 02 '22 15:06 tepene

We use the image that ansible-builder creates as a base image that includes all dependencies we need in production. We use this image as a base for two other images.

One "dev" image that includes ansible-lint, black, and other development tools. We build, test and validate our local role inside the "dev" Container. You can even use this image inside vscode to write your collection code in a environment very close to production.

The third and final image is just the base image with our local role.

no-12 avatar Jun 14 '22 22:06 no-12

All files in context/_build/ will be available in the container during the build step. That's what I'm using for building EEs in collection CIs: I build the collection, copy the collection's .tar.gz file into that directory (after creating it), and then run ansible-builder: https://github.com/ansible-collections/community.dns/blob/main/.github/workflows/ee.yml#L96-L98

felixfontein avatar Jul 15 '22 13:07 felixfontein

@adn1107 You can achieve this functionality with latest version (v3) of Ansible Builder.

The directory structure looks like this -

# tree -L 2 .
.
├── collections
│   └── community-general-5.0.0.tar.gz
├── context
│   ├── _build
│   └── Containerfile
├── ee.yml
└── requirements.yml

3 directories, 6 files

ee.yml -

---
version: 3

images:
  base_image:
    name: quay.io/centos/centos:stream9  # vanilla image!

dependencies:
  python_interpreter:
    package_system: python39
    python_path: /usr/bin/python3.9

  ansible_core:
    package_pip: ansible-core==2.14

  ansible_runner:
    package_pip: ansible-runner==2.2.1   # install from PyPI

  galaxy: requirements.yml

additional_build_files:
  - src: collections/community-general-5.0.0.tar.gz
    dest: mycollections/

requirements.yml -

collections:
  - source: mycollections/community-general-5.0.0.tar.gz
    type: file

Akasurde avatar Apr 27 '23 19:04 Akasurde

I am closing this as per the above comment. Please feel free to open a new issue if the problem persists.

Users should use a v3 execution-environment.yml and build an execution environment to meet their needs from a vanilla base image, or other appropriate base image on the architecture they need.

ansible-builder 3.0.0rc1 has been released and will see a GA release in the near future.

See https://ansible-builder.readthedocs.io/en/latest/definition/

Akasurde avatar Apr 27 '23 19:04 Akasurde