Skip to content

Commit

Permalink
Modify scripts/check_galaxy to return more descriptive error message(…
Browse files Browse the repository at this point in the history
…s) (ansible#695)

Error message from check_galaxy is updated to be more descriptive in case of ansible.cfg parsing error.
  • Loading branch information
brookelew authored Aug 15, 2024
1 parent dc23532 commit 7643d68
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/ansible_builder/_target_scripts/check_galaxy
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ if [ $? -ne 0 ]
then
cat<<EOF
**********************************************************************
ERROR - Missing Ansible installation
ERROR - 'ansible-galaxy' command not functioning as expected
The 'ansible-galaxy' command is not found in the base image. This
image is used to create the intermediary image that performs the
Galaxy collection and role installation process.
There was an error running the 'ansible-galaxy' command. Some
possible causes are 'ansible-core' missing from the base image, an
incorrect 'ansible.cfg', or 'ansible-galaxy' not being available to
the selected Python interpreter. Please use the -vvv option to
examine the build output for any errors.
Ansible must be installed in the base image. If you are using a
recent enough version of the execution environment file, you may
Expand Down
25 changes: 25 additions & 0 deletions test/data/v3/check_galaxy/ee-bad-ansible-cfg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: 3

images:
base_image:
name: quay.io/centos/centos:stream9

dependencies:
ansible_core:
package_pip: ansible-core
ansible_runner:
package_pip: ansible-runner
galaxy:
collections:
- containers.podman

options:
package_manager_path: '/bin/true'

additional_build_files:
- src: ./files/bad_ansible.cfg
dest: configs

additional_build_steps:
prepend_galaxy:
- COPY _build/configs/bad_ansible.cfg /etc/ansible/ansible.cfg
3 changes: 3 additions & 0 deletions test/data/v3/check_galaxy/files/bad_ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Bad ansible.cfg
[defaults]
==?k,sm../a
19 changes: 19 additions & 0 deletions test/integration/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,22 @@ def test_missing_runner(cli, runtime, ee_tag, data_dir, tmp_path):
)

assert "ERROR - Missing Ansible Runner installation" in einfo.value.stdout


@pytest.mark.test_all_runtimes
def test_bad_ansible_cfg(cli, runtime, ee_tag, data_dir, tmp_path):
"""
Test that the check_galaxy script will cause build failure with
incorrect ansible.cfg
"""
ee_def = data_dir / 'v3' / 'check_galaxy' / 'ee-bad-ansible-cfg.yml'

with pytest.raises(subprocess.CalledProcessError) as einfo:
cli(
f'ansible-builder build -c {tmp_path} -f {ee_def} -t {ee_tag} '
f'--container-runtime={runtime} -v3'
)

assert "ERROR - 'ansible-galaxy' command not functioning as expected" in einfo.value.stdout
assert ("ERROR: Error reading config file (/etc/ansible/ansible.cfg): "
"Source contains parsing errors:") in einfo.value.stdout

0 comments on commit 7643d68

Please sign in to comment.