-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathansible.sh
63 lines (56 loc) · 1.66 KB
/
ansible.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
#!/bin/bash
set -e
install_ansible_debian() {
echo "Updating package lists..."
sudo apt update
echo "Installing Ansible..."
sudo apt install -y ansible
}
install_ansible_redhat() {
echo "Installing EPEL repository..."
sudo yum install -y epel-release
echo "Installing Ansible..."
sudo yum install -y ansible
}
install_ansible_macos() {
if ! command -v brew &> /dev/null; then
echo "Homebrew not found. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
echo "Installing Ansible using Homebrew..."
brew install ansible
}
install_ansible_pip() {
echo "Installing Ansible using pip..."
pip install ansible
}
# Detect the operating system
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if [ -f /etc/os-release ]; then
. /etc/os-release
if [[ "$ID" == "ubuntu" || "$ID" == "debian" ]]; then
install_ansible_debian
elif [[ "$ID" == "centos" || "$ID" == "rhel" || "$ID" == "fedora" ]]; then
install_ansible_redhat
else
echo "Unsupported Linux distribution. Trying to install with pip..."
install_ansible_pip
fi
else
echo "Unable to determine Linux distribution. Trying to install with pip..."
install_ansible_pip
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
install_ansible_macos
else
echo "Unsupported operating system: $OSTYPE"
exit 1
fi
# Verify installation
if command -v ansible &> /dev/null; then
echo "Ansible has been successfully installed."
ansible --version
else
echo "Ansible installation failed."
exit 1
fi