forked from catalyst-cloud/catalystcloud-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-ansible.sh
More file actions
executable file
·132 lines (118 loc) · 3.64 KB
/
install-ansible.sh
File metadata and controls
executable file
·132 lines (118 loc) · 3.64 KB
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
#!/bin/bash
# This script installs the latest version of Ansible and the OpenStack
# client libraries in an isolated python virtual environment.
################################################################################
# Functions
################################################################################
help() {
echo "usage: $0 [-v version]"
echo ""
echo "optional arguments:"
echo "-v version, --version version valid versions: latest, stable"
echo "-h, --help prints help information"
}
################################################################################
# Main()
################################################################################
# Parse command line arguments
VERSION="stable"
while [ $# -ge 1 ]; do
case $1 in
--)
# no more arguments
shift
break
;;
-v|--version)
VERSION="$2"
shift
;;
-h|--help)
help
exit 0
;;
*)
echo "Unknown argument $1"
exit 1
;;
esac
shift
done
echo "Installing $VERSION version of Ansible"
# Ensure python-dev is installed.
if [[ -f /etc/debian_version ]] || [[ -f /etc/lsb_release ]]; then
PKG_MANAGER="apt"
PACKAGES="python-dev python-setuptools python-pip gcc git libssl-dev libffi-dev"
elif [[ -f /etc/redhat-release ]] || [[ -f /etc/fedora-release ]]; then
PKG_MANAGER="yum"
PACKAGES="python-devel python-setuptools python-pip gcc git"
fi
sudo $PKG_MANAGER update
sudo $PKG_MANAGER -y install $PACKAGES
# Ensure Python virtualenv and pip are installed.
if ! which pip; then
echo "Could not find python pip on \$PATH"
echo "Installing pip via easy_install (sudo password may be required)"
sudo easy_install pip
if ! which pip; then
echo "Could not install pip using easy_install."
echo "This script requires python pip installed."
exit 1
fi
fi
if ! which virtualenv; then
echo "Could not find virtualenv on \$PATH"
echo "Installing virtualenv via easy_install (sudo password may be required)"
sudo easy_install virtualenv
if ! which virtualenv; then
echo "Could not install virtualenv using easy_install."
echo "This script requires python virtualenv installed."
exit 1
fi
fi
# Create and activate virtual environment for Ansible.
if ! virtualenv ansible; then
echo "Failed to create virtual environment for Ansible at current location."
exit 1
fi
source ansible/bin/activate
# Install the dependencies for Ansible.
if ! pip install paramiko PyYAML Jinja2 httplib2 six pycrypto markupsafe; then
echo "Could not install the dependencies for Ansible."
exit 1
fi
# Install the selected version of Ansible.
if [[ "$VERSION" == "latest" ]]; then
if [[ -d "ansible/ansible" ]]; then
rm -rf ansible/ansible
fi
if ! git clone git://github.com/ansible/ansible.git --recursive ansible/ansible; then
echo "Could not install the latest version of Ansible."
exit 1
fi
elif [[ "$VERSION" == "stable" ]]; then
if ! pip install ansible; then
echo "Could not install the stable version of Ansible."
exit 1
fi
else
echo "Unknown version: $VERSION."
echo "Valid versions are stable and latest."
exit 1
fi
# Install the shade library and the OpenStack client libraries.
if ! pip install shade; then
echo "Could not install the OpenStack client tools and shade"
exit 1
fi
echo
echo "Ansible installed successfully!"
echo "Please remember to activate its virtual environment before using it, by"
echo "running the following command:"
if [[ "$VERSION" == "stable" ]]; then
echo "source $PWD/ansible/bin/activate"
else
echo "source $PWD/ansible/bin/activate && source $PWD/ansible/ansible/hacking/env-setup"
fi
echo
exit 0