-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstack.yaml
145 lines (132 loc) · 5.35 KB
/
stack.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
---
- name: deploy stack
hosts: localhost
gather_facts: False
vars_files:
- settings.yaml
vars:
template: heat_template.yaml
tasks:
- name: create stack
register: stack_create
openstack.cloud.stack:
name: "{{ os.stack_name }}"
state: present
template: "{{ template }}"
parameters:
image_id: "{{ os.image_name }}"
key_name: "{{ os.keypair_name }}"
net: "{{ os.network_name }}"
share_net: "{{ os.share_network_name }}"
share_size: "{{ share_size }}"
share_user: "{{ os.share_user }}"
fast_volume_type: "{{ os.fast_volume_type }}"
slow_volume_type: "{{ os.slow_volume_type }}"
cassandra_volume_size: "{{ instances.cassandranodes.volume_size }}"
sherlock_volume_size: "{{ instances.sherlock.volume_size }}"
db_volume_size: "{{ instances.db.volume_size }}"
frontend_db_volume_size: "{{ instances.frontend_db.volume_size }}"
backend_db_volume_size: "{{ instances.backend_db.volume_size }}"
kafka_pub_size: "{{ instances.kafka_pub.volume_size }}"
n_kafka: "{{ instances.kafka.number|default(1) }}"
n_ingest: "{{ instances.ingest.number|default(1) }}"
n_sherlock: "{{ instances.sherlock.number|default(1) }}"
n_filter: "{{ instances.filter.number|default(1) }}"
n_cassandra: "{{ instances.cassandranodes.number|default(1) }}"
n_frontend_db: "{{ instances.frontend_db.number|default(0) }}"
n_backend_db: "{{ instances.backend_db.number|default(0) }}"
n_parallel_ssh: "{{ instances.parallel_ssh.number|default(0) }}"
create_db: "{{ instances.db.create|default(true) }}"
create_cluster_control: "{{ instances.cluster_control.create|default(false) }}"
create_kafka_pub: "{{ instances.kafka_pub.create|default(true) }}"
create_svc: "{{ instances.svc.create|default(true) }}"
create_web: "{{ instances.web.create|default(true) }}"
flavor_small: "{{ os.flavor_small }}"
flavor_medium: "{{ os.flavor_medium }}"
flavor_large: "{{ os.flavor_large }}"
flavor_xlarge: "{{ os.flavor_xlarge }}"
flavor_kafka: "{{ os.flavor_kafka }}"
flavor_database: "{{ os.flavor_database }}"
flavor_parallel_ssh: "{{ instances.parallel_ssh.flavor }}"
- name: update exports.yaml
template:
src: exports.yaml.j2
dest: exports.yaml
# - name: update exports.yaml
# lineinfile:
# path: exports.yaml
# regexp: "exports"
# line: " exports: {{ item }}"
# loop: |
# [
# {%- for output in stack_create.stack.outputs %}
# {%- if output.description == "Export locations" %}
# {{ output.output_value | regex_replace('\[(.*)\]', '\1') }},
# {%- endif %}
# {%- endfor %}
# ]
- name: update /etc/hosts
become: true
lineinfile:
path: /etc/hosts
regexp: '\s{{ item.hostname }}$'
line: "{{ item.address }} {{ item.hostname }}"
loop: |
[
{%- for output in stack_create.stack.outputs %}
{%- if output.description == "Private IP" %}
{%- if output.output_value %}
{ 'address': '{{ output.output_value }}', 'hostname': '{{ os.stack_name }}-{{ output.output_key }}' },
{%- endif %}
{%- endif %}
{%- if output.description == "Private IP list" %}
{%- for address in output.output_value %}
{ 'address': '{{ address }}', 'hostname': '{{ os.stack_name }}-{{ output.output_key }}-{{ loop.index0 }}' },
{%- endfor %}
{%- endif %}
{%- endfor %}
]
- name: add sections to inventory
ansible.builtin.lineinfile:
path: hosts
line: "[{{ item }}]"
loop: "{{ instances | list }}"
- name: add hosts to inventory
ini_file:
path: hosts
section: "{{ item.role }}"
allow_no_value: true
option: "{{ os.stack_name }}-{{ item.role }}{{ item.suffix }}"
loop: |
[
{%- for role,values in instances.items() %}
{%- if values.number is defined %}
{%- for i in range(0, values.number) %}
{ 'role': '{{ role }}', 'suffix': '-{{ i }}' },
{%- endfor %}
{%- elif values.create %}
{ 'role': '{{ role }}', 'suffix': '' },
{%- endif %}
{%- endfor %}
]
loop_control:
label: "{{ os.stack_name }}-{{ item.role }}{{ item.suffix }}"
# We don't currently have dedicated instances for proxy and api roles
# so add these to the web server
- name: add extra roles in inventory
ini_file:
path: hosts
section: "{{ item }}"
allow_no_value: true
option: "{{ os.stack_name }}-web"
with_items:
- proxy
- api
- name: set state of parallel ssh instances
openstack.cloud.server_action:
action: "{% if instances.parallel_ssh.started %}unshelve{% else %}shelve{% endif %}"
server: "{{ os.stack_name }}-parallel_ssh-{{ item }}"
loop: "{{ range(0, instances.parallel_ssh.number) }}"
# There appears to be a bug somewhere that throws an exception when we update the
# state, but it still works provided we ignore the error
ignore_errors: true