pvc-ansible/create-local-repo.sh

88 lines
3.0 KiB
Bash
Raw Permalink Normal View History

2023-09-01 15:42:27 -04:00
#!/usr/bin/env bash
# Creates a local repo for storing group_vars/files/inventories, with this
# project as a submodule.
echo "This script will create a new repository for storing your local modifications"
echo "and configurations. It will then include the pvc-ansible and pvc-installer "
echo "repositories as submodules for ease of updating and management."
2023-09-01 15:42:27 -04:00
echo
echo -n "Absolute path to new repository ('~', '\$HOME', etc. are NOT supported): "
read target_path
echo
echo "Creating new repo at ${target_path}..."
mkdir -p ${target_path}
pushd ${target_path}
git init .
echo "Adding submodules..."
2023-09-01 15:42:27 -04:00
git submodule add https://github.com/parallelvirtualcluster/pvc-ansible
git submodule add https://github.com/parallelvirtualcluster/pvc-installer
2023-09-01 15:42:27 -04:00
echo "Creating directories and symlinks..."
mkdir files group_vars roles
ln -s ../pvc-ansible/files/default files/default
ln -s ../pvc-ansible/group_vars/default group_vars/default
ln -s ../pvc-ansible/roles/base roles/base
ln -s ../pvc-ansible/roles/pvc roles/pvc
2023-09-01 15:42:28 -04:00
ln -s files ceph
2023-09-01 15:42:29 -04:00
cp -r pvc-ansible/oneshot oneshot
2023-09-01 15:42:27 -04:00
cp pvc-ansible/pvc.yml .
2023-09-01 15:42:28 -04:00
cp pvc-ansible/clusters.yml .
2023-09-01 15:42:29 -04:00
if [[ ! -d files/default ]]; then
cp -r pvc-ansible/files/default files/
fi
2023-09-01 15:42:27 -04:00
touch hosts
cat <<EOF >update-remote.sh
#!/usr/bin/env bash
# Updates the local copy of pvc-ansible
set -o errexit
pushd pvc-ansible
git pull --rebase
git checkout master
2023-09-01 15:42:27 -04:00
popd
pushd pvc-installer
git pull --rebase
git checkout master
popd
git add pvc-ansible pvc-installer
git commit -m "Update submodules from upstream"
2023-09-01 15:42:27 -04:00
EOF
chmod +x update-remote.sh
echo "Adding and performing initial commit..."
git add .
git commit -m "Initial commit of new repository"
popd
echo
echo -e "Success: your new repository has been created at ${target_path}."
echo -e "* You no longer need this copy of the repository and may delete it."
echo -e "* You may edit the initial commit message and author details with the command:"
echo -e " git commit --amend"
echo -e " inside the new repository."
echo -e "* You will need to add a 'git remote' in order to push the new repository."
2023-09-01 15:42:27 -04:00
echo -e "* A copy of the file 'pvc.yml' has been made there, as well as your own 'roles/'"
echo -e " directory, so you may add your own roles and customizations to these files"
echo -e " if you so desire."
echo -e "* An empty 'hosts' inventory along with empty 'group_vars' and 'files'"
echo -e " directories have also been prepared; edit these as required."
echo -e "* You may use the 'update-remote.sh' script in this new repository to keep your"
echo -e " copy of pvc-ansible updated, or use normal git commands to do so."
2023-09-01 15:42:27 -04:00
echo -e "* IMPORTANT: Whenever Ansible creates a new cluster, or if you do so manually,"
echo -e " you must move the files from 'pvc-ansible/files/' to 'files/', AND replace"
echo -e " them with a symlink like so:"
echo -e " cd pvc-ansible/files/"
echo -e " mv cluster ../../files/"
echo -e " ln -s ../../files/cluster"
echo -e " If you do not do so, the files will not be committed and future runs of the"
echo -e " playbooks will not work properly due to how Ansible looks up files."