-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathansible
executable file
·86 lines (75 loc) · 2.12 KB
/
ansible
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
#!/bin/bash
options=""
ssh_key="$HOME/.ssh/id_rsa"
initial_user="root"
target="$1"
shift
case "$target" in
"bootstrap")
if [ -z "$1" ]; then
echo "Please specify the target host(s) !"
exit 1
fi
echo "Bootstraping $@..."
echo
echo -n "Please enter the initial $initial_user password: "
read -s password
echo # Add a Line Feed since the "read -s" do not output it !
# Ask for Red Hat Network credentials
if [ -z "$RHN_LOGIN" ]; then
echo -n "Please enter your RHN login: "
read rhn_login
export RHN_LOGIN="$rhn_login"
fi
if [ -z "$RHN_PASSWORD" ]; then
echo -n "Please enter your RHN password: "
read -s rhn_password
export RHN_PASSWORD="$rhn_password"
echo # Add a Line Feed since the "read -s" do not output it !
fi
if [ -z "$RHN_POOLID" ]; then
echo -n "Please enter your RHN Pool ID: "
read rhn_poolid
export RHN_POOLID="$rhn_poolid"
fi
echo
echo
# Pre-register SSH Host Keys
for host; do
echo "Connecting to $host to register the SSH Host Key !"
LC_ALL=C sshpass -p "$password" ssh -i $ssh_key -o StrictHostKeyChecking=no "$initial_user@$host" /bin/true
done
# Setup authentication
if [ -n "$password" ]; then
options="$options -e ansible_ssh_pass=$password"
else
options="$options -e ansible_ssh_private_key_file=$ssh_key"
fi
# Setup the ssh user
options="$options -e ansible_ssh_user=$initial_user "
# Generate an inventory file "on the fly"
echo "[bootstrap]" > "bootstrap.hosts"
for host; do
echo -e "$host"
done >> "bootstrap.hosts"
ansible-playbook -i "bootstrap.hosts" $options bootstrap.yml
rm -f "bootstrap.hosts"
;;
"play")
if [ -z "$1" ]; then
echo "Please specify the playbook to run !"
exit 1
fi
playbook="$1"
shift
ansible-playbook -i "$playbook.hosts" $options "$@" $playbook.yml
;;
*)
echo "Usage: $0 {bootstrap|play} [options]"
echo
echo "Samples: "
echo " $0 bootstrap machine.example.com"
echo " $0 play allinone"
exit 1
;;
esac