2018-01-30 17:40:25 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -eux -o pipefail
|
|
|
|
|
2019-07-09 21:47:25 +02:00
|
|
|
ansible-playbook setup.yml "$@"
|
2018-02-10 19:48:44 +01:00
|
|
|
|
2020-02-14 21:00:00 +01:00
|
|
|
trap 'ansible-playbook ${ANSIBLE_PLAYBOOK_DIR}/cleanup.yml' EXIT
|
2019-03-28 22:05:56 +01:00
|
|
|
|
2019-10-17 15:21:08 +02:00
|
|
|
# Very simple version test
|
|
|
|
ansible-galaxy --version
|
|
|
|
|
2018-01-30 17:40:25 +01:00
|
|
|
# Need a relative custom roles path for testing various scenarios of -p
|
|
|
|
galaxy_relative_rolespath="my/custom/roles/path"
|
|
|
|
|
|
|
|
# Prep the local git repo with a role and make a tar archive so we can test
|
|
|
|
# different things
|
|
|
|
galaxy_local_test_role="test-role"
|
|
|
|
galaxy_local_test_role_dir=$(mktemp -d)
|
|
|
|
galaxy_local_test_role_git_repo="${galaxy_local_test_role_dir}/${galaxy_local_test_role}"
|
|
|
|
galaxy_local_test_role_tar="${galaxy_local_test_role_dir}/${galaxy_local_test_role}.tar"
|
|
|
|
pushd "${galaxy_local_test_role_dir}"
|
|
|
|
ansible-galaxy init "${galaxy_local_test_role}"
|
|
|
|
pushd "${galaxy_local_test_role}"
|
|
|
|
git init .
|
|
|
|
|
|
|
|
# Prep git, becuase it doesn't work inside a docker container without it
|
|
|
|
git config user.email "tester@ansible.com"
|
|
|
|
git config user.name "Ansible Tester"
|
|
|
|
|
|
|
|
git add .
|
|
|
|
git commit -m "local testing ansible galaxy role"
|
|
|
|
git archive \
|
|
|
|
--format=tar \
|
|
|
|
--prefix="${galaxy_local_test_role}/" \
|
|
|
|
master > "${galaxy_local_test_role_tar}"
|
|
|
|
popd # "${galaxy_local_test_role}"
|
|
|
|
popd # "${galaxy_local_test_role_dir}"
|
|
|
|
|
|
|
|
# Status message function (f_ to designate that it's a function)
|
|
|
|
f_ansible_galaxy_status()
|
|
|
|
{
|
2019-07-09 21:47:25 +02:00
|
|
|
printf "\n\n\n### Testing ansible-galaxy: %s\n" "${@}"
|
2018-01-30 17:40:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Galaxy install test case
|
|
|
|
#
|
|
|
|
# Install local git repo
|
|
|
|
f_ansible_galaxy_status "install of local git repo"
|
|
|
|
galaxy_testdir=$(mktemp -d)
|
|
|
|
pushd "${galaxy_testdir}"
|
|
|
|
|
2019-07-09 21:47:25 +02:00
|
|
|
ansible-galaxy install git+file:///"${galaxy_local_test_role_git_repo}" "$@"
|
2018-01-30 17:40:25 +01:00
|
|
|
|
|
|
|
# Test that the role was installed to the expected directory
|
|
|
|
[[ -d "${HOME}/.ansible/roles/${galaxy_local_test_role}" ]]
|
|
|
|
popd # ${galaxy_testdir}
|
|
|
|
rm -fr "${galaxy_testdir}"
|
|
|
|
|
|
|
|
# Galaxy install test case
|
|
|
|
#
|
|
|
|
# Install local git repo and ensure that if a role_path is passed, it is in fact used
|
|
|
|
f_ansible_galaxy_status "install of local git repo with -p \$role_path"
|
|
|
|
galaxy_testdir=$(mktemp -d)
|
|
|
|
pushd "${galaxy_testdir}"
|
|
|
|
mkdir -p "${galaxy_relative_rolespath}"
|
|
|
|
|
2019-07-09 21:47:25 +02:00
|
|
|
ansible-galaxy install git+file:///"${galaxy_local_test_role_git_repo}" -p "${galaxy_relative_rolespath}" "$@"
|
2018-01-30 17:40:25 +01:00
|
|
|
|
|
|
|
# Test that the role was installed to the expected directory
|
|
|
|
[[ -d "${galaxy_relative_rolespath}/${galaxy_local_test_role}" ]]
|
|
|
|
popd # ${galaxy_testdir}
|
|
|
|
rm -fr "${galaxy_testdir}"
|
|
|
|
|
|
|
|
# Galaxy install test case
|
|
|
|
#
|
|
|
|
# Ensure that if both a role_file and role_path is provided, they are both
|
|
|
|
# honored
|
|
|
|
#
|
|
|
|
# Protect against regression (GitHub Issue #35217)
|
|
|
|
# https://github.com/ansible/ansible/issues/35217
|
|
|
|
|
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"install of local git repo and local tarball with -p \$role_path and -r \$role_file" \
|
|
|
|
"Protect against regression (Issue #35217)"
|
|
|
|
galaxy_testdir=$(mktemp -d)
|
|
|
|
pushd "${galaxy_testdir}"
|
|
|
|
|
|
|
|
git clone "${galaxy_local_test_role_git_repo}" "${galaxy_local_test_role}"
|
2019-07-09 21:47:25 +02:00
|
|
|
ansible-galaxy init roles-path-bug "$@"
|
2018-01-30 17:40:25 +01:00
|
|
|
pushd roles-path-bug
|
|
|
|
cat <<EOF > ansible.cfg
|
|
|
|
[defaults]
|
|
|
|
roles_path = ../:../../:../roles:roles/
|
|
|
|
EOF
|
|
|
|
cat <<EOF > requirements.yml
|
|
|
|
---
|
|
|
|
- src: ${galaxy_local_test_role_tar}
|
|
|
|
name: ${galaxy_local_test_role}
|
|
|
|
EOF
|
|
|
|
|
2019-07-09 21:47:25 +02:00
|
|
|
ansible-galaxy install -r requirements.yml -p roles/ "$@"
|
2018-01-30 17:40:25 +01:00
|
|
|
popd # roles-path-bug
|
|
|
|
|
|
|
|
# Test that the role was installed to the expected directory
|
|
|
|
[[ -d "${galaxy_testdir}/roles-path-bug/roles/${galaxy_local_test_role}" ]]
|
|
|
|
|
|
|
|
popd # ${galaxy_testdir}
|
|
|
|
rm -fr "${galaxy_testdir}"
|
|
|
|
|
2020-02-15 01:51:48 +01:00
|
|
|
|
|
|
|
# Galaxy role list test case
|
|
|
|
#
|
|
|
|
# Basic tests to ensure listing roles works
|
|
|
|
|
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"role list"
|
|
|
|
|
|
|
|
ansible-galaxy role list | tee out.txt
|
|
|
|
ansible-galaxy role list test-role | tee -a out.txt
|
|
|
|
|
|
|
|
[[ $(grep -c '^- test-role' out.txt ) -eq 2 ]]
|
|
|
|
|
|
|
|
|
2019-07-09 21:47:25 +02:00
|
|
|
#################################
|
|
|
|
# ansible-galaxy collection tests
|
|
|
|
#################################
|
|
|
|
|
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"collection init tests to make sure the relative dir logic works"
|
|
|
|
galaxy_testdir=$(mktemp -d)
|
|
|
|
pushd "${galaxy_testdir}"
|
|
|
|
|
|
|
|
ansible-galaxy collection init ansible_test.my_collection "$@"
|
|
|
|
|
|
|
|
# Test that the collection skeleton was created in the expected directory
|
|
|
|
for galaxy_collection_dir in "docs" "plugins" "roles"
|
|
|
|
do
|
|
|
|
[[ -d "${galaxy_testdir}/ansible_test/my_collection/${galaxy_collection_dir}" ]]
|
|
|
|
done
|
|
|
|
|
|
|
|
popd # ${galaxy_testdir}
|
|
|
|
rm -fr "${galaxy_testdir}"
|
|
|
|
|
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"collection init tests to make sure the --init-path logic works"
|
|
|
|
galaxy_testdir=$(mktemp -d)
|
|
|
|
pushd "${galaxy_testdir}"
|
|
|
|
|
|
|
|
ansible-galaxy collection init ansible_test.my_collection --init-path "${galaxy_testdir}/test" "$@"
|
|
|
|
|
|
|
|
# Test that the collection skeleton was created in the expected directory
|
|
|
|
for galaxy_collection_dir in "docs" "plugins" "roles"
|
|
|
|
do
|
|
|
|
[[ -d "${galaxy_testdir}/test/ansible_test/my_collection/${galaxy_collection_dir}" ]]
|
|
|
|
done
|
|
|
|
|
|
|
|
popd # ${galaxy_testdir}
|
|
|
|
|
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"collection build test creating artifact in current directory"
|
|
|
|
|
|
|
|
pushd "${galaxy_testdir}/test/ansible_test/my_collection"
|
|
|
|
|
|
|
|
ansible-galaxy collection build "$@"
|
|
|
|
|
|
|
|
[[ -f "${galaxy_testdir}/test/ansible_test/my_collection/ansible_test-my_collection-1.0.0.tar.gz" ]]
|
|
|
|
|
|
|
|
popd # ${galaxy_testdir}/ansible_test/my_collection
|
|
|
|
|
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"collection build test to make sure we can specify a relative path"
|
|
|
|
|
|
|
|
pushd "${galaxy_testdir}"
|
|
|
|
|
|
|
|
ansible-galaxy collection build "test/ansible_test/my_collection" "$@"
|
|
|
|
|
|
|
|
[[ -f "${galaxy_testdir}/ansible_test-my_collection-1.0.0.tar.gz" ]]
|
|
|
|
|
|
|
|
# Make sure --force works
|
|
|
|
ansible-galaxy collection build "test/ansible_test/my_collection" --force "$@"
|
|
|
|
|
|
|
|
[[ -f "${galaxy_testdir}/ansible_test-my_collection-1.0.0.tar.gz" ]]
|
|
|
|
|
2019-07-24 04:38:32 +02:00
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"collection install from local tarball test"
|
|
|
|
|
2020-01-09 20:24:36 +01:00
|
|
|
ansible-galaxy collection install "ansible_test-my_collection-1.0.0.tar.gz" -p ./install "$@" | tee out.txt
|
2019-07-24 04:38:32 +02:00
|
|
|
|
|
|
|
[[ -f "${galaxy_testdir}/install/ansible_collections/ansible_test/my_collection/MANIFEST.json" ]]
|
|
|
|
grep "Installing 'ansible_test.my_collection:1.0.0' to .*" out.txt
|
|
|
|
|
|
|
|
|
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"collection install with existing collection and without --force"
|
|
|
|
|
2020-01-09 20:24:36 +01:00
|
|
|
ansible-galaxy collection install "ansible_test-my_collection-1.0.0.tar.gz" -p ./install "$@" | tee out.txt
|
2019-07-24 04:38:32 +02:00
|
|
|
|
|
|
|
[[ -f "${galaxy_testdir}/install/ansible_collections/ansible_test/my_collection/MANIFEST.json" ]]
|
|
|
|
grep "Skipping 'ansible_test.my_collection' as it is already installed" out.txt
|
|
|
|
|
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"collection install with existing collection and with --force"
|
|
|
|
|
2020-01-09 20:24:36 +01:00
|
|
|
ansible-galaxy collection install "ansible_test-my_collection-1.0.0.tar.gz" -p ./install --force "$@" | tee out.txt
|
|
|
|
|
|
|
|
[[ -f "${galaxy_testdir}/install/ansible_collections/ansible_test/my_collection/MANIFEST.json" ]]
|
|
|
|
grep "Installing 'ansible_test.my_collection:1.0.0' to .*" out.txt
|
|
|
|
|
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"ansible-galaxy with a sever list with an undefined URL"
|
|
|
|
|
|
|
|
ANSIBLE_GALAXY_SERVER_LIST=undefined ansible-galaxy collection install "ansible_test-my_collection-1.0.0.tar.gz" -p ./install --force "$@" 2>&1 | tee out.txt || echo "expected failure"
|
|
|
|
|
|
|
|
grep "No setting was provided for required configuration plugin_type: galaxy_server plugin: undefined setting: url" out.txt
|
|
|
|
|
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"ansible-galaxy with an empty server list"
|
|
|
|
|
|
|
|
ANSIBLE_GALAXY_SERVER_LIST='' ansible-galaxy collection install "ansible_test-my_collection-1.0.0.tar.gz" -p ./install --force "$@" | tee out.txt
|
2019-07-24 04:38:32 +02:00
|
|
|
|
|
|
|
[[ -f "${galaxy_testdir}/install/ansible_collections/ansible_test/my_collection/MANIFEST.json" ]]
|
|
|
|
grep "Installing 'ansible_test.my_collection:1.0.0' to .*" out.txt
|
|
|
|
|
2020-02-14 21:00:00 +01:00
|
|
|
|
|
|
|
## ansible-galaxy collection list tests
|
|
|
|
|
|
|
|
# Create more collections and put them in various places
|
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"setting up for collection list tests"
|
|
|
|
|
|
|
|
rm -rf ansible_test/* install/*
|
|
|
|
|
|
|
|
NAMES=(zoo museum airport)
|
|
|
|
for n in "${NAMES[@]}"; do
|
|
|
|
ansible-galaxy collection init "ansible_test.$n"
|
|
|
|
ansible-galaxy collection build "ansible_test/$n"
|
|
|
|
done
|
|
|
|
|
|
|
|
ansible-galaxy collection install ansible_test-zoo-1.0.0.tar.gz
|
|
|
|
ansible-galaxy collection install ansible_test-museum-1.0.0.tar.gz -p ./install
|
|
|
|
ansible-galaxy collection install ansible_test-airport-1.0.0.tar.gz -p ./local
|
|
|
|
|
|
|
|
# Change the collection version and install to another location
|
|
|
|
sed -i -e 's#^version:.*#version: 2.5.0#' ansible_test/zoo/galaxy.yml
|
|
|
|
ansible-galaxy collection build ansible_test/zoo
|
|
|
|
ansible-galaxy collection install ansible_test-zoo-2.5.0.tar.gz -p ./local
|
|
|
|
|
|
|
|
export ANSIBLE_COLLECTIONS_PATHS=~/.ansible/collections:${galaxy_testdir}/local
|
|
|
|
|
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"collection list all collections"
|
|
|
|
|
|
|
|
ansible-galaxy collection list -p ./install | tee out.txt
|
|
|
|
|
|
|
|
[[ $(grep -c ansible_test out.txt) -eq 4 ]]
|
|
|
|
|
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"collection list specific collection"
|
|
|
|
|
|
|
|
ansible-galaxy collection list -p ./install ansible_test.airport | tee out.txt
|
|
|
|
|
|
|
|
[[ $(grep -c 'ansible_test\.airport' out.txt) -eq 1 ]]
|
|
|
|
|
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"collection list specific collection found in multiple places"
|
|
|
|
|
|
|
|
ansible-galaxy collection list -p ./install ansible_test.zoo | tee out.txt
|
|
|
|
|
|
|
|
[[ $(grep -c 'ansible_test\.zoo' out.txt) -eq 2 ]]
|
|
|
|
|
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"collection list all with duplicate paths"
|
|
|
|
|
|
|
|
ansible-galaxy collection list -p ~/.ansible/collections | tee out.txt
|
|
|
|
|
|
|
|
[[ $(grep -c '# /root/.ansible/collections/ansible_collections' out.txt) -eq 1 ]]
|
|
|
|
|
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"collection list invalid collection name"
|
|
|
|
|
|
|
|
ansible-galaxy collection list -p ./install dirty.wraughten.name "$@" 2>&1 | tee out.txt || echo "expected failure"
|
|
|
|
|
|
|
|
grep 'ERROR! Invalid collection name' out.txt
|
|
|
|
|
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"collection list path not found"
|
|
|
|
|
|
|
|
ansible-galaxy collection list -p ./nope "$@" 2>&1 | tee out.txt || echo "expected failure"
|
|
|
|
|
|
|
|
grep '\[WARNING\]: - the configured path' out.txt
|
|
|
|
|
|
|
|
f_ansible_galaxy_status \
|
|
|
|
"collection list missing ansible_collections dir inside path"
|
|
|
|
|
|
|
|
mkdir emptydir
|
|
|
|
|
|
|
|
ansible-galaxy collection list -p ./emptydir "$@"
|
|
|
|
|
|
|
|
rmdir emptydir
|
|
|
|
|
|
|
|
unset ANSIBLE_COLLECTIONS_PATHS
|
|
|
|
|
|
|
|
## end ansible-galaxy collection list
|
|
|
|
|
|
|
|
|
2019-07-09 21:47:25 +02:00
|
|
|
popd # ${galaxy_testdir}
|
|
|
|
|
|
|
|
rm -fr "${galaxy_testdir}"
|
2018-01-30 17:40:25 +01:00
|
|
|
|
|
|
|
rm -fr "${galaxy_local_test_role_dir}"
|