Skip to content

Commit 6534c08

Browse files
authored
Merge pull request #47 from stackhpc/full-deploy
Add a script to perform a complete multi-node deployment
2 parents 513761e + db59522 commit 6534c08

File tree

4 files changed

+170
-4
lines changed

4 files changed

+170
-4
lines changed

README.rst

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,45 @@ Make sure to define `ssh_key_path` to point to the location of the SSH key in us
189189
VNI should be much smaller than the officially supported limit of 16,777,215 as we encounter errors when attempting to bring interfaces up that use a high VNI.
190190
You must set `vault_password_path`; this should be set to the path to a file containing the Ansible vault password.
191191

192-
Deployment
193-
==========
192+
Deployment: The fast(er) way
193+
============================
194+
195+
The `scripts/deploy.sh` script provides a fully automated deployment method
196+
that can be used to perform all steps from infrastructure deployment through to
197+
Tempest testing without user interaction. Any errors encountered will be
198+
reported and halt the deployment.
199+
200+
This script makes use of the `ansible/deploy-openstack.yml` Ansible playbook
201+
that runs the `deploy-openstack.sh` script in a `tmux` session on the Ansible
202+
control host. The session is logged to `~/tmux.kayobe\:0.log` on the Ansible
203+
control host. Use `less -r ~/tmux.kayobe\:0.log` to view the logs in their
204+
original colourful glory.
205+
206+
Note that this approach requires all Terraform, Ansible, Kayobe and OpenStack
207+
configuration to be provided in advance. For Kayobe and OpenStack
208+
configuration, this may be achieved by providing suitable branches for the
209+
kayobe-config and openstack-config repositories and referencing them in
210+
`ansible/vars/defaults.yml`.
211+
212+
To tear down the cluster immediately after a successful deployment, combine
213+
with the `scripts/tear-down.sh` script.
214+
215+
.. code-block:: console
216+
217+
./scripts/deploy.sh && ./scripts/tear-down.sh -a -k
218+
219+
Note that this will not tear down the cluster if deployment fails, allowing for
220+
debugging the issue and/or retrying.
221+
222+
Deployment: The slow(er) way
223+
============================
224+
225+
This section describes a more hands-on, interactive deployment method. It may
226+
be useful to gain a better understanding of how the deployment works, modify
227+
the deployment process in some way, or iterate on configuration.
228+
229+
Terraform Deploy infrastructure using Terraform
230+
-----------------------------------------------
194231

195232
Generate a plan:
196233

@@ -207,7 +244,7 @@ Apply the changes:
207244
You should have requested a number of resources to be spawned on Openstack.
208245

209246
Configure Ansible control host
210-
==============================
247+
------------------------------
211248

212249
Run the configure-hosts.yml playbook to configure the Ansible control host.
213250

@@ -223,7 +260,7 @@ This playbook sequentially executes 2 other playbooks:
223260
These playbooks are tagged so that they can be invoked or skipped using `tags` or `--skip-tags` as required.
224261

225262
Deploy OpenStack
226-
================
263+
----------------
227264

228265
Once the Ansible control host has been configured with a Kayobe/OpenStack configuration you can then begin the process of deploying OpenStack.
229266
This can be achieved by either manually running the various commands to configure the hosts and deploy the services or automated by using the generated `deploy-openstack.sh` script.

ansible/deploy-openstack.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
- name: Deploy OpenStack
3+
hosts: ansible_control
4+
gather_facts: false
5+
vars:
6+
# 6 hours should be enough...
7+
deployment_timeout_s: "{{ 6 * 60 * 60 }}"
8+
lock_path: /tmp/deploy-openstack.lock
9+
rc_path: /tmp/deploy-openstack.rc
10+
tmux_session: kayobe
11+
tmux_log_path: "~/tmux.{{ tmux_session }}:0.log"
12+
connection_info: |
13+
# SSH to Ansible control host
14+
ssh {{ ansible_user }}@{{ ansible_host }}
15+
# Either: Attach to the tmux session
16+
tmux -t {{ tmux_session }} attach
17+
# Or: Follow the log file
18+
less -r {{ tmux_log_path }}
19+
vars_files:
20+
- vars/defaults.yml
21+
tasks:
22+
- name: Check if tmux session exists
23+
command: tmux has-session -t {{ tmux_session }}
24+
failed_when: false
25+
register: session_check
26+
27+
- name: Create a new tmux window and log to a file
28+
command: >-
29+
tmux new -d -s {{ tmux_session }}\;
30+
pipe-pane -t {{ tmux_session }} -o 'cat >> ~/tmux.#S:#P.log'
31+
when: session_check.rc != 0
32+
33+
# deploy-openstack.sh uses a "lock" directory to ensure that only one
34+
# instance can run concurrently.
35+
- name: Check that no deployment is in progress
36+
stat:
37+
path: "{{ lock_path }}"
38+
register: lock_stat
39+
40+
- name: Fail if a deployment is in progress
41+
fail:
42+
msg: |
43+
Refusing to deploy because a deployment is currently in progress.
44+
If you are sure this is not the case, remove the {{ lock_path }}
45+
directory and run this playbook again.
46+
when: lock_stat.stat.exists
47+
48+
- name: Run deploy-openstack.sh in tmux window
49+
command: >-
50+
tmux send -t {{ tmux_session }}.0 './deploy-openstack.sh' ENTER
51+
52+
- name: Show how to follow deployment progress
53+
debug:
54+
msg: |
55+
Deployment of OpenStack has started.
56+
To follow progress:
57+
58+
{{ connection_info }}
59+
60+
- name: Wait for deploy-openstack.sh to start
61+
pause:
62+
seconds: 30
63+
64+
- name: Wait for deployment to complete
65+
stat:
66+
path: "{{ lock_path }}"
67+
register: lock_stat
68+
until: not lock_stat.stat.exists
69+
retries: "{{ (deployment_timeout_s | int / 10) | int }}"
70+
delay: 10
71+
failed_when: false
72+
73+
# deploy-openstack.sh writes an exit code to a file. 0 is success
74+
- name: Check deployment result
75+
slurp:
76+
path: "{{ rc_path }}"
77+
register: rc_slurp
78+
79+
- name: Fail if deployment was unsuccessful
80+
fail:
81+
msg: |
82+
Deployment or testing of OpenStack was unsuccessful.
83+
To see results:
84+
85+
{{ connection_info }}
86+
when: rc_slurp.content | b64decode != "0"

scripts/deploy.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
# This script performs a complete multi-node cluster deployment.
4+
5+
set -eux
6+
set -o pipefail
7+
8+
# Check for dependencies
9+
if ! type terraform; then
10+
echo "Unable to find Terraform"
11+
exit 1
12+
fi
13+
if ! type ansible; then
14+
echo "Unable to find Ansible"
15+
exit 1
16+
fi
17+
18+
# Deploy infrastructure using Terraform.
19+
terraform plan
20+
terraform apply -auto-approve
21+
22+
# Configure the Ansible control host.
23+
ansible-playbook -i ansible/inventory.yml ansible/configure-hosts.yml
24+
25+
# Deploy OpenStack.
26+
ansible-playbook -i ansible/inventory.yml ansible/deploy-openstack.yml

templates/deploy-openstack.tpl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ declare -A config_directories=(
2424
)
2525

2626
tempest_dir="$HOME/tempest-artifacts"
27+
lock_path=/tmp/deploy-openstack.lock
28+
rc_path=/tmp/deploy-openstack.rc
2729

2830
function activate_virt_env () {
2931
set +u
@@ -37,6 +39,18 @@ function activate_kayobe_env () {
3739
set -u
3840
}
3941

42+
# Use a "lock" directory to ensure that only one instance of this script can run concurrently.
43+
if mkdir "$lock_path"; then
44+
trap "rmdir $lock_path" EXIT
45+
else
46+
echo "Refusing to deploy because a deployment is currently in progress."
47+
echo "If you are sure this is not the case, remove the $lock_path directory and run this script again."
48+
exit 1
49+
fi
50+
51+
# Write an exit code to a file to allow Ansible to report the result.
52+
echo 1 >$rc_path
53+
4054
activate_virt_env "kayobe"
4155
activate_kayobe_env
4256

@@ -174,3 +188,6 @@ if [[ $(wc -l < $tempest_dir/failed-tests) -ne 0 ]]; then
174188
fi
175189

176190
echo "Tempest testing successful"
191+
192+
# Report success.
193+
echo 0 >$rc_path

0 commit comments

Comments
 (0)