-
Notifications
You must be signed in to change notification settings - Fork 2
Infrastructure-Deployment #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 103 commits
645e3a2
5b8bd80
18e5d28
7bb2cd9
e97a5bd
d4f9786
0fec8b3
644d46f
93a2a2f
b15ebf1
0921854
fd1e533
baa2521
2f36b84
c29c28c
63c8f54
4351735
6a0f55e
bacaa2f
f72a422
7403414
f666fed
1e1bdbe
e6969d2
73e4f9e
d834bb6
6a3cea8
608881f
b4096ed
4fa6cbb
d934190
3d3324e
6f921ca
09be066
ac40ab6
ff3f864
a75a201
f1c84f9
5514ce2
ebd2ae4
a3bb3e4
a1585d5
fbb5968
ca48124
acd6d1c
0fa648b
a6b6306
76672b8
c087cb7
1de8778
8248634
5aea5ab
5bdbcdb
0094547
021d3eb
4c7f736
06fdbd7
3657300
6a1c393
68159d2
dd8874c
e0c9720
b15fccb
4f89a78
c0f733a
ea11995
4fab3af
a3e7b2d
57756dd
bde16cd
ab7e903
c8ac249
b0f2932
98d6872
17c0ca2
69846b4
1dce1b5
879e67d
d9d60bd
8dc1d58
fa6fffc
c8ba8d0
c0dff50
ceabfe2
a40845e
5a7c94b
4519eab
232ae60
6fa2086
00ab6fb
6bedaf8
775b7f1
305fc34
cee87a5
1cddc5f
acf6248
f987bd8
257fdce
a8bec13
6b8eb6f
b257275
e9b5c85
8b27ac1
b12c713
07368ad
21a0f7d
eecef28
93ddb5b
4d5d2f1
d91b092
0f92e61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[defaults] | ||
stdout_callback = yaml | ||
callbacks_enabled = timer, profile_tasks, profile_roles | ||
host_key_checking = False | ||
pipelining = True | ||
forks = 30 | ||
deprecation_warnings=False | ||
roles_path = roles | ||
|
||
[ssh_connection] | ||
ssh_args = -o ControlMaster=auto -o ControlPersist=60s |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
resource "openstack_compute_keypair_v2" "keypair" { | ||
name = var.multinode_keypair | ||
public_key = file(var.ssh_public_key) | ||
public_key = var.ssh_public_key | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will impact other multinode users. Could we instead write out the key to a file before getting here? |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# The default Terraform state key for backends that support it | ||
terraform_state_key: "cluster/{{ cluster_id }}/tfstate" | ||
|
||
# Set up the terraform backend | ||
# This setup allows us to use the Consul backend when enabled without any changes | ||
#terraform_backend_type: 'local' | ||
terraform_backend_type: "{{ 'consul' if 'CONSUL_HTTP_ADDR' in ansible_env else 'local' }}" | ||
terraform_backend_config_defaults: | ||
consul: | ||
path: "{{ terraform_state_key }}" | ||
gzip: "true" | ||
local: {} | ||
terraform_backend_config: "{{ terraform_backend_config_defaults[terraform_backend_type] }}" | ||
|
||
# These variables control the location of the Terraform binary | ||
terraform_binary_directory: "{{ playbook_dir }}/bin" | ||
terraform_binary_path: "{{ terraform_binary_directory }}/terraform" | ||
|
||
# This controls the location where the Terraform files are rendered | ||
terraform_project_path: "{{ playbook_dir }}" | ||
|
||
# Indicates whether the Terraform operation is reconciling or removing resources | ||
# Valid values are 'present' and 'absent' | ||
terraform_state: "{{ cluster_state | default('present') }}" | ||
|
||
cluster_ssh_user: "{{ ssh_user }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see this used anywhere There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,63 @@ | ||||||
--- | ||||||
|
||||||
- hosts: localhost | ||||||
tasks: | ||||||
- name: Show Playbook Directory | ||||||
debug: | ||||||
msg: "{{ playbook_dir }}" | ||||||
|
||||||
- name: Template Terraform files into project directory | ||||||
template: | ||||||
src: terraform.tfvars.j2 | ||||||
dest: "{{ playbook_dir }}/terraform.tfvars" | ||||||
|
||||||
- name: Template Terraform userdata.cfg.tpl files into project template directory | ||||||
template: | ||||||
src: "{{ playbook_dir }}/templates/userdata.cfg.tpl.j2" | ||||||
dest: "{{ playbook_dir }}/templates/userdata.cfg.tpl" | ||||||
|
||||||
# Provision the infrastructure The CaaS puts hosts for accessing the OpenStack | ||||||
# API into the 'openstack' group | ||||||
- hosts: openstack | ||||||
roles: | ||||||
- cluster_infra | ||||||
|
||||||
- hosts: localhost | ||||||
tasks: | ||||||
# Check whether an ans_vlt_pwd variable is defined and if so, save it into a | ||||||
# file called '~/vault.password'. If it doesn't exist, create a the | ||||||
# '~/vault.password' file with ans_vlt_pwd = "password_not_set" as the | ||||||
# password. | ||||||
- name: Create vault password file | ||||||
vars: | ||||||
ans_dflt: 'default_password' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it makes sense to have a default here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have considered putting this in the UI meta interface, however, the UI parameter's interpretation of This should not be the place where an actual password/secret should be provided, due to the obvious lack of security. This is for just when the user enters nothing. Maybe I can change it to:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Has been removed all together. |
||||||
ansible.builtin.copy: | ||||||
content: "{{ ans_vlt_pwd | default( ans_dflt , true ) }}" | ||||||
dest: "~/vault.password" | ||||||
mode: 0600 | ||||||
|
||||||
# If openstack_deploy is true then continue if not end the playbook. | ||||||
|
||||||
# Import the playbook to start configuring the multi-node hosts. | ||||||
- name: Configure hosts and deploy ansible | ||||||
import_playbook: ansible/configure-hosts.yml | ||||||
when: openstack_deploy == true | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should do this unconditionally There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this matter even when just deploying the VMs? |
||||||
|
||||||
|
||||||
- hosts: ansible_control | ||||||
vars: | ||||||
ansible_pipelining: true | ||||||
ansible_ssh_pipelining: true | ||||||
Comment on lines
+44
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have pipelining in ansible.cfg There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not entirely sure if they would be carried over when switching to an external host which then calls another instance of ansible itself. I am also not confident in which |
||||||
tasks: | ||||||
- name: Deploy OpenStack. | ||||||
ansible.builtin.command: | ||||||
cmd: "bash ~/deploy-openstack.sh" | ||||||
when: openstack_deploy == true | ||||||
|
||||||
# This is to get the ip of the ansible-controller host. | ||||||
- hosts: localhost | ||||||
tasks: | ||||||
- debug: var=outputs | ||||||
vars: | ||||||
outputs: | ||||||
cluster_access_ip: "{{ hostvars[groups['openstack'][0]].cluster_gateway_ip }}" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if we can assume that the first host in the openstack group is the ansible control host. Is there an ansible_control group? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We define the output of the The reason for not hard coding it in place is because in the |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,10 @@ output "ansible_control_access_ip_v4" { | |
value = openstack_compute_instance_v2.ansible_control.access_ip_v4 | ||
} | ||
|
||
output "cluster_gateway_ip" { | ||
value = openstack_compute_instance_v2.ansible_control.access_ip_v4 | ||
} | ||
|
||
output "seed_access_ip_v4" { | ||
value = openstack_compute_instance_v2.seed.access_ip_v4 | ||
} | ||
|
@@ -75,38 +79,94 @@ resource "local_file" "deploy_openstack" { | |
file_permission = "0755" | ||
} | ||
|
||
resource "ansible_host" "control_host" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing these will break the manual deployment. |
||
name = openstack_compute_instance_v2.ansible_control.access_ip_v4 | ||
groups = ["ansible_control"] | ||
output "cluster_nodes" { | ||
description = "A list of the cluster nodes and their IP addresses which will be used by the Ansible inventory" | ||
value = concat( | ||
[ | ||
{ | ||
name = openstack_compute_instance_v2.ansible_control.name | ||
ip = openstack_compute_instance_v2.ansible_control.access_ip_v4 | ||
groups = ["ansible_control"] | ||
variables = { | ||
ansible_user = var.ssh_user | ||
} | ||
} | ||
], | ||
flatten([ | ||
for node in openstack_compute_instance_v2.compute: { | ||
name = node.name | ||
ip = node.access_ip_v4 | ||
groups = ["compute"] | ||
variables = { | ||
ansible_user = var.ssh_user | ||
} | ||
} | ||
]), | ||
flatten([ | ||
for node in openstack_compute_instance_v2.controller: { | ||
name = node.name | ||
ip = node.access_ip_v4 | ||
groups = ["controllers"] | ||
variables = { | ||
ansible_user = var.ssh_user | ||
} | ||
} | ||
]), | ||
[{ | ||
name = openstack_compute_instance_v2.seed.name | ||
ip = openstack_compute_instance_v2.seed.access_ip_v4 | ||
groups = ["seed"] | ||
variables = { | ||
ansible_user = var.ssh_user | ||
} | ||
}], | ||
flatten([ | ||
for node in openstack_compute_instance_v2.storage: { | ||
name = node.name | ||
ip = node.access_ip_v4 | ||
groups = ["storage"] | ||
variables = { | ||
ansible_user = var.ssh_user | ||
} | ||
} | ||
]) | ||
) | ||
} | ||
|
||
resource "ansible_host" "compute_host" { | ||
for_each = { for host in openstack_compute_instance_v2.compute : host.name => host.access_ip_v4 } | ||
name = each.value | ||
groups = ["compute"] | ||
} | ||
# Template of all the hosts' configuration which can be used to generate Ansible varables. | ||
|
||
resource "ansible_host" "controllers_hosts" { | ||
for_each = { for host in openstack_compute_instance_v2.controller : host.name => host.access_ip_v4 } | ||
name = each.value | ||
groups = ["controllers"] | ||
} | ||
# resource "ansible_host" "control_host" { | ||
# name = openstack_compute_instance_v2.ansible_control.access_ip_v4 | ||
# groups = ["ansible_control"] | ||
# } | ||
|
||
resource "ansible_host" "seed_host" { | ||
name = openstack_compute_instance_v2.seed.access_ip_v4 | ||
groups = ["seed"] | ||
} | ||
# resource "ansible_host" "compute_host" { | ||
# for_each = { for host in openstack_compute_instance_v2.compute : host.name => host.access_ip_v4 } | ||
# name = each.value | ||
# groups = ["compute"] | ||
# } | ||
|
||
resource "ansible_host" "storage" { | ||
for_each = { for host in openstack_compute_instance_v2.storage : host.name => host.access_ip_v4 } | ||
name = each.value | ||
groups = ["storage"] | ||
} | ||
# resource "ansible_host" "controllers_hosts" { | ||
# for_each = { for host in openstack_compute_instance_v2.controller : host.name => host.access_ip_v4 } | ||
# name = each.value | ||
# groups = ["controllers"] | ||
# } | ||
|
||
resource "ansible_group" "cluster_group" { | ||
name = "cluster" | ||
children = ["compute", "ansible_control", "controllers", "seed", "storage"] | ||
variables = { | ||
ansible_user = var.ssh_user | ||
} | ||
} | ||
# resource "ansible_host" "seed_host" { | ||
# name = openstack_compute_instance_v2.seed.access_ip_v4 | ||
# groups = ["seed"] | ||
# } | ||
|
||
# resource "ansible_host" "storage" { | ||
# for_each = { for host in openstack_compute_instance_v2.storage : host.name => host.access_ip_v4 } | ||
# name = each.value | ||
# groups = ["storage"] | ||
# } | ||
|
||
# resource "ansible_group" "cluster_group" { | ||
# name = "cluster" | ||
# children = ["compute", "ansible_control", "controllers", "seed", "storage"] | ||
# variables = { | ||
# ansible_user = var.ssh_user | ||
# } | ||
# } |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is already a requirements.yml in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
collections: | ||
- name: https://github.com/stackhpc/ansible-collection-terraform | ||
type: git | ||
version: 8c7acce4538aab8c0e928972155a2ccb5cb1b2a1 | ||
- name: cloud.terraform | ||
- name: ansible.posix | ||
roles: | ||
- src: mrlesmithjr.manage_lvm |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
|
||
- name: Install Terraform binary | ||
include_role: | ||
name: stackhpc.terraform.install | ||
|
||
- name: Make Terraform project directory | ||
file: | ||
path: "{{ terraform_project_path }}" | ||
state: directory | ||
|
||
- name: Write backend configuration | ||
copy: | ||
content: | | ||
terraform { | ||
backend "{{ terraform_backend_type }}" { } | ||
} | ||
dest: "{{ terraform_project_path }}/backend.tf" | ||
|
||
# Patching in this appliance is implemented as a switch to a new base image | ||
# So unless explicitly patching, we want to use the same image as last time | ||
# To do this, we query the previous Terraform state before updating | ||
- block: | ||
- name: Get previous Terraform state | ||
stackhpc.terraform.terraform_output: | ||
binary_path: "{{ terraform_binary_path }}" | ||
project_path: "{{ terraform_project_path }}" | ||
backend_config: "{{ terraform_backend_config }}" | ||
register: cluster_infra_terraform_output | ||
|
||
- name: Extract image from Terraform state | ||
set_fact: | ||
cluster_previous_image: "{{ cluster_infra_terraform_output.outputs.cluster_image.value }}" | ||
when: '"cluster_image" in cluster_infra_terraform_output.outputs' | ||
when: | ||
- terraform_state == "present" | ||
- cluster_upgrade_system_packages is not defined or not cluster_upgrade_system_packages | ||
|
||
|
||
- name: Provision infrastructure | ||
include_role: | ||
name: stackhpc.terraform.infra |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../requirements.yml |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,6 @@ packages: | |
- git | ||
- vim | ||
- tmux | ||
ssh_authorized_keys: | ||
- "{{ cluster_deploy_ssh_public_key }}" | ||
- "{{ cluster_user_ssh_public_key }}" | ||
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These won't be defined in manual deployments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be a bit cleaner to create a Terraform input for these, rather than templating twice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are the SSH keys injected into the VM instance and shouldn't be needed for the manual deployment, therefore they should be set as empty during the manual deployment and ignored. This, again, is something that requires testing. |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to clearly link this file to the azimuth app. You could either rename it or put it in a role with other azimuth specific things. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is linked in the This did give me the idea that maybe all files which are massively altered for the Azimuth deployment can be placed in a folder as |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
prefix = "{{ cluster_name }}" | ||
|
||
ansible_control_vm_flavor = "general.v1.small" | ||
ansible_control_vm_name = "ansible-control" | ||
ansible_control_disk_size = 25 | ||
|
||
seed_vm_flavor = "general.v1.small" | ||
seed_disk_size = 25 | ||
|
||
multinode_flavor = "general.v1.medium" | ||
multinode_image = "{{ multinode_image }}" | ||
multinode_keypair = "MaxMNKP" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't work for other people. Does Azimuth not provide a keypair name to use? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variable is one that should be provided by the user, as it should be a keypair for the user who the multinode is being created for. This is because the keypair which would be provided by Azimuth would create two issues:
|
||
multinode_vm_network = "stackhpc-ipv4-geneve" | ||
multinode_vm_subnet = "stackhpc-ipv4-geneve-subnet" | ||
compute_count = "2" | ||
controller_count = "3" | ||
compute_disk_size = 25 | ||
controller_disk_size = 25 | ||
Comment on lines
+17
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unlikely to be large enough for a real deployment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I agree. This is just for the deployment of the VMs without OpenStack so it seemed unneccessary for me to request such large volumes for testing to see whether the App was capable of deploying VMs. The storage config is reverted for the branch which is concerned about deploying multinodes with OpenStack, however, these volumes will soon be a user defined input option. |
||
|
||
ssh_public_key = "{{ cluster_user_ssh_public_key }}" | ||
ssh_user = "{{ ssh_user }}" | ||
|
||
storage_count = "3" | ||
storage_flavor = "general.v1.small" | ||
storage_disk_size = 25 | ||
|
||
deploy_wazuh = false | ||
infra_vm_flavor = "general.v1.small" | ||
infra_vm_disk_size = 25 |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
terraform { | ||
required_version = ">= 0.14" | ||
backend "local" { | ||
} | ||
required_providers { | ||
openstack = { | ||
source = "terraform-provider-openstack/openstack" | ||
version = "1.49.0" | ||
} | ||
ansible = { | ||
source = "ansible/ansible" | ||
version = "1.1.0" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be interested to know what in here was actually necessary.