project-config/playbooks/proposal/sync_openstack_ansible_common_files.sh
Jesse Pretorius 18e54ff4c7 proposal/OSA: Sync the contents of the sync folder
We have an emerging need to synchronise a common set of tasks across
roles. While it may sometimes make sense to create a role for this
sort of thing, the overhead of doing so would be greater than simply
copying the file between roles. We're also finding include_role to
be somewhat buggy, especially when used from inside a role.

This patch adds the ability to copy a set of files from the source [1]
to the same path (without the 'sync' prefix) in the destination roles,
abiding by the same rules as all other synchronised files.

[1] openstack/openstack-ansible/tests/sync
Relates-to: https://review.openstack.org/579527
Change-Id: I598ff6aae50e6570d5f262c830c4be10f1cc0b75
2018-07-06 15:46:43 +00:00

71 lines
2.3 KiB
Bash

#!/bin/bash -xe
#
# Copyright 2017, SUSE LINUX GmbH.
#
# 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.
# Copy common files from the openstack-ansible-tests repository
set -eu
OSA_PROJECT=${1}
# Careful of what you put here.
declare -ra files_to_sync=(run_tests.sh bindep.txt Vagrantfile tests/tests-repo-clone.sh .gitignore sync/tasks/*)
excluded_projects=
exclude_project() {
excluded_projects+="$1 "
}
# Always exclude openstack-ansible-tests repository. This is not
# necessary because OSA_PROJECT should never be "openstack-ansible-tests"
# but it can serve as an example for users who may add more
# projects in the future.
exclude_project "openstack-ansible-tests"
check_and_ignore() {
for z in $(echo ${excluded_projects} | tr ' ' '\n'); do
[[ $1 == $z ]] && return 0
done
return 1
}
for src_path in ${files_to_sync[@]}; do
# If the source repo does not have the file to copy
# then skip to the next file. This covers the situation
# where this script runs against old branches which
# do not have the same set of files. If the src_path
# is 'sync/tasks/*' because the folder does not exist
# then it will fail this test too.
[[ ! -e ${src_path} ]] && continue
# For the sync/* files in the array, the destination
# path is different to the source path. To work out
# the destination path we remove the 'sync/' prefix.
dst_path=${src_path#sync/}
# If the target repo does not have such a file already
# then it's probably best to leave it alone.
[[ ! -e ${OSA_PROJECT}/${dst_path} ]] && continue
# Skip the project if it is in the excluded list
check_and_ignore ${OSA_PROJECT} && continue
# We don't preserve anything from the target repo.
# We simply assume that all OSA projects need the same
# $files_to_sync
cp ${src_path} ${OSA_PROJECT}/${dst_path}
done
exit 0