debian.ansible.basics/install.sh

41 lines
1.2 KiB
Bash
Raw Normal View History

2023-08-23 14:15:21 +02:00
#!/bin/bash
set -e
# on fresh install remove cdrom-repo and install sudo if not available
[ -s /usr/bin/sudo ] || su -c "sed -i '/cdrom/d' /etc/apt/sources.list ; apt update ; apt -y install sudo"
# add user to sudo group it not
if ! id | grep -q '(sudo)'
then
su -c "/usr/sbin/usermod -a -G sudo ${USER}"
# use sudo group and restart this script
exec sg sudo -c "bash $0"
exit $?
fi
which ansible >/dev/null 2>&1 || sudo apt-get -y install ansible git
2023-08-23 16:25:20 +02:00
#sudo ansible-galaxy collection list | grep -q community.general || sudo ansible-galaxy collection install community.general
sudo ansible-galaxy collection install community.general
2023-08-23 14:15:21 +02:00
cd
rm -rf $(hostname -s)-git
mkdir $(hostname -s)-git
cd $(hostname -s)-git
for playbook in $PLAYBOOKS
do
2024-02-07 14:14:59 +01:00
if [ -z "${GITSRVURL}" ]
then
2024-02-07 14:21:45 +01:00
git clone https://gitea.ds9.dedyn.io/olli/${playbook}.git
2024-02-07 14:14:59 +01:00
else
2024-02-07 14:22:53 +01:00
git clone ${GITSRVURL}/${playbook}.git
2024-02-07 14:14:59 +01:00
fi
2023-08-23 14:15:21 +02:00
[ -s /etc/dohardening ] || rm -f ${playbook}/hardening.yml
2024-02-07 14:06:16 +01:00
if ls ${playbook}/*ansible*.yml >/dev/null 2>&1
2024-02-07 13:50:40 +01:00
then
sudo ansible-playbook --connection=local --inventory $(hostname), --limit $(hostname) ${playbook}/*ansible*.yml
else
sudo ansible-playbook --connection=local --inventory $(hostname), --limit $(hostname) ${playbook}/*.yml
fi
2023-08-23 14:15:21 +02:00
done