-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_ansible.sh
134 lines (111 loc) · 3.5 KB
/
install_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
############## Installing for Centos 7, Ubuntu 16.04 ##############
############## Variables ##############
#export red='\033[0;91m'
#export green='\033[0;92m'
#export yellow='\033[0;93m'
#export nc='\033[0m'
export red=$(tput setaf 1)
export green=$(tput setaf 2)
export nc=$(tput sgr0)
# Update installed package
#M_PLATFORM=`python -mplatform |grep -Eo "Ubuntu"`
M_PLATFORM_UBUNTU=`python -mplatform |grep -Eo "Ubuntu"`
M_PLATFORM_CENTOS=`python -mplatform |grep -Eo "centos"`
M_PLATFORM_FEDORA=`python -mplatform |grep -Eo "fedora"`
if [[ $EUID -ne 0 ]]; then
echo -e "${red}[ERROR ]${nc} Please run this script with root permission"
if [[ $M_PLATFORM_UBUNTU == "Ubuntu" ]]; then
echo -e "[INFO ] Type: \"sudo -s\" before running script"
exit 1;
elif [[ $M_PLATFORM_CENTOS == "centos" ]]; then
echo -e "[INFO ] Type: \"su -\" before running script"
exit 1;
elif [[ $M_PLATFORM_FEDORA == "fedora" ]]; then
echo -e "[INFO ] Type: \"su -\" before running script"
exit 1;
else
echo -e "${red}[ERROR ]${nc}This could not ecognize any distro of Linux, please check it again"
exit 1;
fi
fi
EXITCODE=0
function CHECK_STATUS {
if [[ $EXITCODE == 0 ]]; then
echo -e " ${green}DONE${nc}"
else
echo -e " ${red}ERROR${nc}"
echo "[INFO ] Please check error login /tmp/install_ansible.log"
exit 1;
fi
}
function OS_UPDATE {
echo -n "[INFO ] Updating OS: "
if [[ $M_PLATFORM_UBUNTU == "Ubuntu" ]]; then
apt-get update -y &>> /tmp/install_ansible.log
elif [[ $M_PLATFORM_CENTOS == "centos" ]]; then
yum update -y &>> /tmp/install_ansible.log
fi
EXITCODE=$?
CHECK_STATUS
}
function INSTALL_PACKAGES {
echo "[INFO ] Install Packages:"
if [[ $M_PLATFORM_UBUNTU == "Ubuntu" ]]; then
echo -n "- Installing Python, Python-pip: "
apt-get -y install python python-pip &>> /tmp/install_ansible.log
EXITCODE=$?
CHECK_STATUS
echo -n "[INFO ] - Installing Ansible: "
apt-get -y install ansible &>> /tmp/install_ansible.log
EXITCODE=$?
CHECK_STATUS
echo -n "[INFO ] - Installing GIT: "
apt-get -y install git &>> /tmp/install_ansible.log
EXITCODE=$?
CHECK_STATUS
elif [[ $M_PLATFORM_CENTOS == "centos" ]]; then
echo -n "[INFO ] - Installing Epel Repository: "
yum -y install epel-release &>> /tmp/install_ansible.log
EXITCODE=$?
CHECK_STATUS
echo -n "[INFO ] - Installing Python, Python-pip package: "
yum -y install python python-pip > /dev/null
EXITCODE=$?
CHECK_STATUS
echo -n "[INFO ] - Installing Ansible package: "
yum -y install ansible &>> /tmp/install_ansible.log
EXITCODE=$?
CHECK_STATUS
echo -n "[INFO ] - Installing GIT package: "
yum -y install git &>> /tmp/install_ansible.log
EXITCODE=$?
CHECK_STATUS
fi
}
function PRE_CONFIG {
echo -n "[INFO ] Config default folder for Ansible (/opt): "
chmod -R 777 /opt
EXITCODE=$?
CHECK_STATUS
}
function INSTALL_REQUIREMENT {
echo -n "[INFO ] Install jxmlease: "
pip install jxmlease &>> /tmp/install_ansible.log
EXITCODE=$?
CHECK_STATUS
echo -n "[INFO ] Install Junox-PyEZ Module: "
pip install junos-eznc &>> /tmp/install_ansible.log
EXITCODE=$?
CHECK_STATUS
}
function GIT_CLONE {
echo -n "[INFO ] Git Clone Demo Ansible Repository: "
git clone https://github.com/tuhoanganh/SVTECH-Junos-Ansible.git /opt/SVTECH-Junos-Ansible &>> /tmp/install_ansible.log
echo -e " ${green}DONE${nc}"
}
OS_UPDATE
INSTALL_PACKAGES
PRE_CONFIG
INSTALL_REQUIREMENT
GIT_CLONE