-
Notifications
You must be signed in to change notification settings - Fork 39
/
run.sh
executable file
·78 lines (73 loc) · 2.52 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
# Just run the playbook, defaults to included sample inventory.
# Pass in any regular ansible-playbook commands.
#
# For example, us another inventory, limit hosts and set extra args:
# ./run.sh --inventory ~/my_inventory --limit kvmhost,guests -e virt_infra_state=undefined
DIR="$(dirname "$(readlink -f "${0}")")"
source /etc/os-release
# Check for dependencies
if ! type ansible-playbook &>/dev/null ; then
read -r -p "Ansible missing, install it? [y/N]: " answer
if [[ "${answer,,}" != "y" && "${answer,,}" != "yes" ]] ; then
echo "OK, please install it and retry."
exit 1
fi
DISTRO=${ID_LIKE:-${ID}}
case "${DISTRO,,}" in
centos)
if [[ "${VERSION_ID}" -eq "7" ]] ; then
PKG_MGR=yum
fi
echo sudo ${PKG_MGR:-dnf} -y install epel-release
sudo ${PKG_MGR:-dnf} -y install epel-release
echo sudo ${PKG_MGR:-dnf} -y install ansible
sudo ${PKG_MGR:-dnf} -y install ansible
;;
fedora)
echo sudo dnf -y install ansible
sudo dnf -y install ansible
;;
debian)
echo "Installing Ansible from Ubuntu PPA..."
echo sudo apt install -y gnupg2
sudo apt install -y gnupg2
echo "echo 'deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main' | sudo tee -a /etc/apt/sources.list"
grep -q ansible /etc/apt/sources.list || echo 'deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main' | sudo tee -a /etc/apt/sources.list
echo sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
echo sudo apt update
sudo apt update
echo sudo apt install -y ansible
sudo apt install -y ansible
;;
ubuntu)
echo "Installing Ansible from PPA..."
echo sudo apt install -y software-properties-common
sudo apt install -y software-properties-common
echo sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt-add-repository --yes --update ppa:ansible/ansible
echo sudo apt install -y ansible
sudo apt install -y ansible
;;
opensuse|opensuse-leap)
echo sudo zypper install -y ansible
sudo zypper install -y ansible
;;
*)
echo "${ID} not supported, please install manually"
exit 1
;;
esac
if [[ "$?" -ne 0 ]]; then
echo "Something went wrong, sorry."
exit 1
fi
echo "Continuing with Ansible playbook!"
fi
if [[ -z "$(ls -1 "${DIR}/roles/ansible-role-virt-infra/")" ]]; then
echo "Role git submodule not found, pulling now.."
git submodule init
git submodule update
fi
exec ansible-playbook "${DIR}/virt-infra.yml" ${@}