-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
ansible-install.sh
executable file
·134 lines (111 loc) · 3.1 KB
/
ansible-install.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
134
#!/usr/bin/env bash
###############################################################################
# Debug Options
###############################################################################
# Short form: set -u
# set -o nounset
# Short form: set -e
# set -o errexit
# Print a helpful message if a pipeline with non-zero exit code causes the
# script to exit as described above.
# trap 'echo "Aborting due to errexit on line $LINENO. Exit code: $?" >&2' ERR
# Allow the above trap be inherited by all functions in the script.
#
# Short form: set -E
# set -o errtrace
# Return value of a pipeline is the value of the last (rightmost) command to
# exit with a non-zero status, or zero if all commands in the pipeline exit
# successfully.
# set -o pipefail
###############################################################################
# Program Variables
###############################################################################
# Set $IFS to only newline and tab.
# http://www.dwheeler.com/essays/filenames-in-shell.html
IFS=$'\n\t'
###############################################################################
# Program Functions
###############################################################################
_verify_ansible() {
if [ -x "$(command -v ansible-galaxy)" ]; then
# install role
ansible-galaxy install git+https://github.com/elastic/ansible-elastic-cloud-enterprise.git
else
echo "ERROR: Ansible isn't installed on this machine, aborting ece installation"
exit 1
fi
}
_write_ansible_playbook() {
cat << PLAYBOOK > ./ece.yml
---
- hosts: primary
gather_facts: true
roles:
- ansible-elastic-cloud-enterprise
vars:
ece_primary: true
ece_version: ${ece-version}
- hosts: secondary
gather_facts: true
roles:
- ansible-elastic-cloud-enterprise
vars:
ece_roles: [director, coordinator, proxy, allocator]
ece_version: ${ece-version}
- hosts: tertiary
gather_facts: true
roles:
- ansible-elastic-cloud-enterprise
vars:
ece_roles: [director, coordinator, proxy, allocator]
ece_version: ${ece-version}
PLAYBOOK
}
_write_ansible_hosts() {
cat << HOSTS_FILE > ./hosts
[primary]
${ece-server0}
[primary:vars]
availability_zone=${ece-server0-zone}
[secondary]
${ece-server1}
[secondary:vars]
availability_zone=${ece-server1-zone}
[tertiary]
${ece-server2}
[tertiary:vars]
availability_zone=${ece-server2-zone}
[aws:children]
primary
secondary
tertiary
[aws:vars]
ansible_ssh_private_key_file=${key}
ansible_user=${user}
ansible_become=yes
device_name=${device}
HOSTS_FILE
}
_run_ansible() {
export ANSIBLE_HOST_KEY_CHECKING=False
ansible-playbook -i hosts ece.yml
}
###############################################################################
# Main
###############################################################################
# _main()
#
# Usage:
# _main [<options>] [<arguments>]
#
# Description:
# Entry point for the program, handling basic option parsing and dispatching.
_main() {
_verify_ansible
_write_ansible_playbook
_write_ansible_hosts
sleep ${sleep-timeout}
_run_ansible
}
# Call `_main` after everything has been defined.
_main "$@"