Created
August 3, 2023 09:36
-
-
Save kriipke/c2caad6fc7c5e4793f8cc895571996ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -ex | |
# THIS SCRIPT PROVISIONS A NEW ANSIBLE ROLE INSIDE A | |
# VIRTUAL ENVIRONMENT VIA PIPENV FOR USE WITH MOLECULE + VAGRANT | |
ROLE_NAME=${1:?} | |
ROLE_NAMEPACE=${2:?} | |
ROLE_PATH=/opt/src/ansible-${ROLE_NAME}-role/ | |
sudo dnf install -y "python3.11" "python3.11-pip" | |
sudo mkdir -p $ROLE_PATH && sudo chown $USER $ROLE_PATH | |
cd $ROLE_PATH | |
# install libvirt | |
sudo dnf install -y yum-utils qemu-kvm libvirt virt-install virt-viewer | |
for drv in qemu network nodedev nwfilter secret storage interface; do | |
sudo systemctl start virt${drv}d{,-ro,-admin}.socket | |
done | |
# confirm host is ready for virtualization | |
sudo virt-host-validate | |
# install vagrant | |
sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo | |
sudo dnf install -y vagrant | |
# install/configure virtual environment | |
python3.11 -m pip install --user --upgrade pip | |
python3.11 -m pip install --user --upgrade pipenv | |
pipenv --python 3.11 install ansible molecule python-vagrant "molecule-plugins[vagrant]" | |
ansible --version | |
molecule --version | |
vagrant --version | |
# create molecule role | |
molecule init role "${ROLE_NAMESPACE}.${ROLE_NAME}" --driver-name vagrant |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment