-
Notifications
You must be signed in to change notification settings - Fork 7
/
run.sh
executable file
·52 lines (41 loc) · 1.15 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
#!/bin/bash
ansible --version
# Install Ansible
if [ $? -ne 0 ]; then
sudo apt-get update
if [ $? -eq 0 ]; then
sudo apt-get install -qqy software-properties-common
sudo apt-add-repository ppa:ansible/ansible -y
sudo apt-get update
sudo apt-get install -qqy ansible
else
sudo yum install -y epel-release
sudo yum install -y ansible
if [ $? -ne 0 ]; then
sudo pip install ansible
fi
# allow nginx permission to access localhost docker
setsebool httpd_can_network_connect on -P
fi
fi
# Install Remote Roles
if ! sudo ansible-galaxy list | grep -q 'nginx'; then
sudo ansible-galaxy install -r requirements.yml
sudo chown -R $USER ~/.ansible
fi
group=docker
cmd="ansible-playbook -i hosts ./playbook.yml"
# If not in 'docker' group, need to switch to
# group to allow to docker ops as non-root user
if [ $(id -gn) != $group ]; then
if ! grep -q $group /etc/group; then
sudo groupadd docker
fi
if ! groups | grep -q $group; then
sudo usermod -aG docker $USER
exec sg $group "$cmd --extra-vars \"$1\""
return
fi
fi
echo $cmd
$cmd --extra-vars "$1"