Skip to content
Snippets Groups Projects
Commit 97f60be5 authored by Klaus Frank's avatar Klaus Frank
Browse files

Drop support for ansible-galaxy and move fully/only to git submodule

parent 30f0491e
No related branches found
No related tags found
No related merge requests found
Pipeline #19793 failed
Showing
with 90 additions and 137 deletions
[submodule "roles/external/ansible-prerequirements"]
path = roles/external/ansible-prerequirements
url = ../../agowa338-ansible/ansible-prerequirements.git
branch = master
[submodule "roles/external/ansible-hostname"]
path = roles/external/ansible-hostname
url = ../../agowa338-ansible/ansible-hostname.git
branch = master
[submodule "roles/external/Stouts.sudo"]
path = roles/external/Stouts.sudo
url = ../../agowa338-ansible/Stouts.sudo.git
branch = master
[submodule "roles/external/openssh"]
path = roles/external/openssh
url = ../../agowa338-ansible/openssh.git
branch = master
[submodule "roles/external/ansible-locale"]
path = roles/external/ansible-locale
url = ../../agowa338-ansible/ansible-locale.git
branch = master
[submodule "roles/external/ansible-role-pacman"]
path = roles/external/ansible-role-pacman
url = ../../agowa338-ansible/ansible-role-pacman.git
branch = master
pre-commit.sh
\ No newline at end of file
#!/bin/bash
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
ROOT_DIR=$(cd "$DIR/../../" && pwd)
EXTERNAL_ROLE_DIR="$ROOT_DIR/roles/external"
ROLES_REQUIREMNTS_FILE="$ROOT_DIR/roles/roles_requirements.yml"
git_diff_command_output=$(git diff --name-only --staged $ROLES_REQUIREMNTS_FILE 2>&1)
git_diff_exit_code=$?
git_diff_command_output_lines=$(echo $git_diff_command_output | wc -l )
if [ $git_diff_exit_code -eq 128 ]
then
: # do nothing, requirements file does not exist
elif [ $git_diff_exit_code -eq 0 ] && [ $git_diff_command_output_lines -gt 0 ]
then
$ROOT_DIR/extensions/setup/role_update.sh
elif [ $git_diff_exit_code -eq 0 ]
then
: # no new module
else
# unknown error
exit $git_diff_exit_code
fi
exit 0
#!/bin/bash
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
ROOT_DIR=$(cd "$DIR/../../" && pwd)
EXTERNAL_ROLE_DIR="$ROOT_DIR/roles/external"
ROLES_REQUIREMNTS_FILE="$ROOT_DIR/roles/roles_requirements.yml"
git_diff_command_output=$(git diff --name-only --staged $ROLES_REQUIREMNTS_FILE 2>&1)
git_diff_exit_code=$?
git_diff_command_output_lines=$(echo $git_diff_command_output | wc -l )
if [ $git_diff_exit_code -eq 128 ]
then
: # do nothing, requirements file does not exist
elif [ $git_diff_exit_code -eq 0 ] && [ $git_diff_command_output_lines -gt 0 ]
then
$ROOT_DIR/extensions/setup/role_update.sh
elif [ $git_diff_exit_code -eq 0 ]
then
: # no new module
else
# unknown error
exit $git_diff_exit_code
fi
exit 0
from io import open
from yaml import load
from os import (listdir, path)
from subprocess import check_output as call
def get_immediate_subdirectories(a_dir):
return [name for name in listdir(a_dir)
if path.isdir(path.join(a_dir, name))]
class galaxy_to_submodule(object):
def __init__(self, roles_requirements_filepath='roles/roles_requirements.yml'):
self.roles_requirements_filepath = roles_requirements_filepath
file_handler = open(self.roles_requirements_filepath, 'r')
galaxy_roles = ''
for line in file_handler.readlines():
galaxy_roles += line
file_handler.close()
self.galaxy_roles = load(galaxy_roles)
def remove_all_submodules(self):
call(['git', 'submodule', 'deinit', '--force', '--all'])
submodules_status = call(['git', 'submodule', 'status'])
# if not empty
if submodules_status.count('\n') != 0:
submodules_status = submodules_status.split('\n')
del submodules_status[-1]
for submodule_status in submodules_status:
a, submodule_path = submodule_status.split(' ')
call(['git', 'rm', '--force', submodule_path])
def add_all_submodules(self):
parent_git_url_prefix, parent_git_url_subfolder = call(
['git', 'remote', 'get-url', 'origin']).replace('\n', '').split(':')
parent_git_subfolder_depth = parent_git_url_subfolder.count('/') + 1
relative_git_path_prefix = ''
for i in range(0, parent_git_subfolder_depth):
relative_git_path_prefix += "../"
for role in self.galaxy_roles:
call(['git', 'submodule', 'add', '--force', '-b',
role['version'], role['src']], cwd='roles/external')
for role in get_immediate_subdirectories('roles/external'):
# GitLab workaroung, modules need to have relative path in order for the runner to pull them. Otherwise they don't have the access tocken embedded.
config_node = 'submodule.roles/external/REPOSITORY.url'.replace(
'REPOSITORY', role)
role_url = call(
['git', 'config', '-f', '.gitmodules', config_node]).replace('\n', '')
role_url = role_url.replace(
parent_git_url_prefix + ":", relative_git_path_prefix)
call(['git', 'config', '-f', '.gitmodules', config_node, role_url])
call(['git', 'submodule', 'sync', '--recursive'])
call(['git', 'submodule', 'update', '--init',
'--remote', '--force', '--recursive'])
call(['git', 'add', '.gitmodules'])
if __name__ == '__main__':
gts = galaxy_to_submodule()
gts.remove_all_submodules()
gts.add_all_submodules()
......@@ -12,6 +12,7 @@ python-dev
python-pip
sudo
apt-transport-https
openssl
# Required python packages
python-yaml
......
pip
git-lfs
pyOpenSSL
# Ansible
ansible
......
......@@ -25,47 +25,14 @@ cleanup() {
}
trap "cleanup" ERR INT TERM
# Check roles req file
[[ ! -f "$ROLES_REQUIREMNTS_FILE" ]] && msg_exit "roles_requirements '$ROLES_REQUIREMNTS_FILE' does not exist or permssion issue.\nPlease check and rerun."
remove_external_roles() {
# Remove existing external roles
if [ -d "$EXTERNAL_ROLE_DIR" ]
then
pushd "$EXTERNAL_ROLE_DIR" > /dev/null
if [ "$(pwd)" == "$EXTERNAL_ROLE_DIR" ]
then
echo "Removing current roles in '$EXTERNAL_ROLE_DIR/*'"
rm -rf *
git clean -xddff "$EXTERNAL_ROLE_DIR"
git checkout "$EXTERNAL_ROLE_DIR"
else
msg_exit "Path error could not change dir to $EXTERNAL_ROLE_DIR"
fi
popd > /dev/null
fi
}
update_with_galaxy() {
# Install roles
ansible-galaxy install -r "$ROLES_REQUIREMNTS_FILE" --force --no-deps -p "$EXTERNAL_ROLE_DIR"
git submodule deinit --all --force
}
update_with_git_submodule() {
pushd "$ROOT_DIR" > /dev/null
python2 $ROOT_DIR/extensions/setup/ansiblegalaxygitsubmodule.py
popd > /dev/null
git submodule update --init --recursive --remote
git submodule sync --recursive
}
# Check if git submodule or ansible-galaxy should be used.
# The requirements file is written into git submodules using a pre-commit hook (which invokes this script)
remove_external_roles
update_with_git_submodule
#if [[ -z "$(which ansible-galaxy)" ]]
#then
# remove_external_roles
# update_with_galaxy
#else
# msg_exit "Ansible-galaxy can be used for initialization of your external roles.\nExternal roles are not initialized!"
#fi
......@@ -72,9 +72,12 @@ install_pip_packages_deb() {
if ! which sudo > /dev/null 2>&1
then
echo "You're $(whoami)"
rm -rf /usr/lib/python2.7/dist-packages/OpenSSL
rm -rf /usr/lib/python2.7/dist-packages/pyOpenSSL-0.15.1.egg-info
pip install --upgrade $(cat $REQUIRED_PIP_PACKAGES_DEB | grep -v '#' | grep -v '^ *$')
else
sudo apt update
sudo rm -rf /usr/lib/python2.7/dist-packages/OpenSSL
sudo rm -rf /usr/lib/python2.7/dist-packages/pyOpenSSL-0.15.1.egg-info
sudo pip install --upgrade $(cat $REQUIRED_PIP_PACKAGES_DEB | grep -v '#' | grep -v '^ *$')
fi
fi
......
Subproject commit 4b16b90bfe676698b7729fb6c50a42a7f3de3af4
Subproject commit 1b279529cce0dd85ac4e8682553e3eddb40ddb93
Subproject commit a612a7cefe059bf717635b5e98baf9355859169b
Subproject commit ba9a3868d465a7e9319e97acad44e5584b47f51f
Subproject commit 85a50fe9056a5ebbe14f4f96a101b5f46aee2668
Subproject commit 5ed6a7c77ab72a38630b8ed312cdd36e53906b98
- src: 'git+https://chaos.expert/agowa338-ansible/ansible-prerequirements.git'
version: master
- src: 'git+https://chaos.expert/agowa338-ansible/ansible-hostname.git'
version: master
- src: 'git+https://chaos.expert/agowa338-ansible/Stouts.sudo.git'
version: master
- src: 'git+https://chaos.expert/agowa338-ansible/openssh.git'
version: master
- src: 'git+https://chaos.expert/agowa338-ansible/ansible-locale.git'
version: master
- src: 'git+https://chaos.expert/agowa338-ansible/ansible-role-pacman.git'
version: master
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment