-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathinstall_scaling_manager.yaml
210 lines (209 loc) · 5.93 KB
/
install_scaling_manager.yaml
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
---
- name: Add new host
hosts: localhost
tasks:
- name: Add new host to etc file
become_user: root
become: yes
lineinfile:
path: /etc/hosts
line: "{{ hostvars[item]['ansible_private_host'] }} {{ item }}.{{ domain_name }} {{ item }}"
state: present
create: yes
with_items: "{{ groups['new_node'] }}"
tags: add_host
- name: Build and Pack Scaling Manager
hosts: localhost
tasks:
- name: Build the Scaling Manager
command: make build
become: yes
- name: Pack the Scaling Manager
command: make pack
become: yes
tags: build_and_pack
- name: Install make
hosts: all
tasks:
- name: Install make
become: yes
shell:
cmd: apt install make
tags: install_make
- name: Install Scaling Manager
hosts: all
tasks:
- name: Transfer the Binaries
become: yes
copy:
src: "{{ src_bin_path | default('/usr/local/scaling_manager_lib') }}/{{ item }}"
dest: "{{ dest_bin_path | default('/usr/local/scaling_manager_lib/') }}"
owner: '{{ user | default("ubuntu") }}'
group: '{{ group | default("ubuntu") }}'
with_items:
- scaling_manager.tar.gz
- GNUmakefile
- name: Check if make is installed
become: yes
command: dpkg-query -W -f='${Status}' make | grep 'install ok installed'
register: is_make_installed
failed_when: no
changed_when: no
- name: Install make if not installed
become: yes
apt:
name: make
state: latest
update_cache: yes
when: is_make_installed.rc != 0
- name: Check if ansible is installed
become: yes
command: dpkg-query -W -f='${Status}' ansible | grep 'install ok installed'
register: is_ansible_installed
failed_when: no
changed_when: no
- name: Install ansible if not installed
become_user: root
become: yes
raw: (sudo apt -y update && sudo apt -y install software-properties-common && sudo add-apt-repository --yes --update ppa:ansible/ansible && sudo apt -y install ansible)
register: task_result
until: task_result.rc == 0
retries: 5
delay: 30
when: is_ansible_installed.rc != 0
- name: Installing Scalling Manager
shell:
args:
cmd: make install USER_NAME={{ user | default('ubuntu') }} GROUP={{ group | default('ubuntu') }}
chdir: "{{ dest_bin_path | default('/usr/local/scaling_manager_lib/') }}"
become: yes
tags: install
- name: Update secret
hosts: all
tasks:
- name: Transfer the secret file
become: yes
copy:
src: "{{ secret_path | default('/usr/local/scaling_manager_lib/.secret.txt') }}"
dest: /usr/local/scaling_manager_lib/
owner: '{{ user | default("ubuntu") }}'
group: '{{ group | default("ubuntu") }}'
tags: update_secret
- name: Update Config
hosts: all
tasks:
- name: Transfer the Config file
become: yes
copy:
src: "{{ config_path | default('/usr/local/scaling_manager_lib/config.yaml') }}"
dest: /usr/local/scaling_manager_lib/
owner: '{{ user | default("ubuntu") }}'
group: '{{ group | default("ubuntu") }}'
tags: update_config
- name: Update pem
hosts: all
tasks:
- name: Transfer the PEM file
become: yes
copy:
src: "{{ pem_path | default('/usr/local/scaling_manager_lib/user.pem') }}"
dest: /usr/local/scaling_manager_lib/user.pem
owner: '{{ user | default("ubuntu") }}'
group: '{{ group | default("ubuntu") }}'
mode: 0600
tags: update_pem
- name: Start Scaling manager
hosts: all
tasks:
- name: Starting Scaling Manager Service
become: yes
systemd:
name: scaling_manager
state: started
# - name: Starting crypto Service
# become: yes
# systemd:
# name: crypto_sm
# state: started
# - name: Starting fetchmetrics Service
# become: yes
# systemd:
# name: fetchmetrics
# state: started
tags: start
- name: Stop Scaling manager
hosts: all
tasks:
- name: Stopping Scaling Manager Service
become: yes
systemd:
name: scaling_manager
state: stopped
# - name: Stopping crypto Service
# become: yes
# systemd:
# name: crypto_sm
# state: stopped
# - name: Stopping fetchmetrics Service
# become: yes
# systemd:
# name: fetchmetrics
# state: stopped
tags: stop
- name: Restart Scaling manager
hosts: all
tasks:
- name: Restarting Scaling Manager Service
become: yes
systemd:
name: scaling_manager
state: restarted
tags: restart
- name: Scaling manager status
hosts: all
tasks:
- name: Getting the status of Scaling Manager Service
become: yes
shell: systemctl status scaling_manager.service
register: sm_service_status
ignore_errors: yes
- name: Printing the status of Scaling Manager Service
debug:
var: sm_service_status.stdout_lines
tags: status
- name: Uninstall Scaling Manager
hosts: all
tasks:
- name: Transfer the Makefile
become: yes
copy:
src: "{{ src_bin_path | default('/usr/local/scaling_manager_lib') }}/GNUmakefile"
dest: "/tmp"
owner: '{{ user | default("ubuntu") }}'
group: '{{ group | default("ubuntu") }}'
- name: Uninstalling Scalling Manager
shell:
args:
cmd: make uninstall
chdir: "/tmp"
become: yes
tags: uninstall
- name: populate inventory.yaml
hosts: localhost
tasks:
- name:
uri:
url: "http://{{ master_node_ip }}:9200/_cat/nodes"
user: "{{ os_user }}"
password: "{{ os_pass }}"
return_content: true
register: os_nodes_out
- debug:
var: os_nodes_out.content
- set_fact:
os_nodes: "{{ os_nodes_out.content.split('\n') | select() | list }}"
- shell: rm -f inventory.yaml
- shell: echo "{{ item.split(' ')[0] }} ansible_host={{ item.split(' ')[0] }} ansible_user={{ user | default('ubuntu') }} ansible_ssh_common_args='-o StrictHostKeyChecking=no'" >> inventory.yaml
with_items:
"{{ os_nodes }}"
tags: populate_inventory_yaml