#!/bin/bash
# Copyright (c) 2023 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#####################################################################
# Script to validate that Ansible Galaxy is installed on the system.
#####################################################################

set -x

ansible-galaxy --version

if [ $? -ne 0 ]
then
    cat<<EOF
**********************************************************************
ERROR - 'ansible-galaxy' command not functioning as expected

  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
  use the 'dependencies.ansible_core' configuration option to install
  Ansible for you, or use 'additional_build_steps' to manually do
  this yourself. Alternatively, use a base image with Ansible already
  installed.
**********************************************************************
EOF
    exit 1
fi

exit 0
