diff --git a/sysadmin/grid5000/cassandra/terraform/create_environment.sh b/sysadmin/grid5000/cassandra/terraform/create_environment.sh new file mode 100644 index 0000000..38d2525 --- /dev/null +++ b/sysadmin/grid5000/cassandra/terraform/create_environment.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +echo "*********** Preparing environment" +# TODO install terraform if not present + +python3 -m venv ~/.venv +source ~/.venv/bin/activate +pip install ansible + +echo "*********** Reserve and initialize nodes" +terraform apply + +# TODO status check + +echo "*********** Terraform output" +terraform output --json | jq '' | tee > environment.json diff --git a/sysadmin/grid5000/cassandra/terraform/local/terraform.tf b/sysadmin/grid5000/cassandra/terraform/local/terraform.tf new file mode 100644 index 0000000..5457f4f --- /dev/null +++ b/sysadmin/grid5000/cassandra/terraform/local/terraform.tf @@ -0,0 +1,13 @@ +terraform { + required_version = ">= 0.13" + required_providers { + libvirt = { + source = "multani/libvirt" + version = "0.6.3-1+4" + } + } +} + +provider "libvirt" { + uri = "qemu:///system" +} diff --git a/sysadmin/grid5000/cassandra/terraform/main.tf b/sysadmin/grid5000/cassandra/terraform/main.tf index 1022512..ba3f65b 100644 --- a/sysadmin/grid5000/cassandra/terraform/main.tf +++ b/sysadmin/grid5000/cassandra/terraform/main.tf @@ -1,23 +1,67 @@ provider "grid5000" { # Uses Restfully credentials restfully_file = pathexpand("~/.grid5000.yml") } +resource "grid5000_job" "reservation" { + name = "swh" + site = var.site + command = "sleep ${var.sleep_time}" + resources = "{(type='disk' or type='default') AND cluster='${var.cluster}'}/nodes=${var.total_node_count},walltime=${var.walltime}" + types = ["cosystem", "container"] +} + resource "grid5000_job" "cassandra" { - name = "terraform" - site = "lille" - command = "sleep 1h" - resources = "{\"cluster\"='chifflet'}/nodes=2,walltime=0:10:00" - types = ["deploy"] + name = "swh" + site = var.site + command = "sleep ${var.sleep_time}" + resources = "/nodes=${var.cassandra_node_count},walltime=${var.cassandra_walltime}" + types = ["inner=${grid5000_job.reservation.id}", "deploy"] } -resource "grid5000_deployment" "my_deployment" { +resource "grid5000_deployment" "cassandra_deployment" { site = grid5000_job.cassandra.site environment = "debian10-x64-base" nodes = grid5000_job.cassandra.assigned_nodes - key = file("~/.ssh/id_rsa.pub") + key = file("~/.ssh/grid5000.pub") +} + +resource "null_resource" "cassandra_install" { + depends_on = [grid5000_deployment.cassandra_deployment] + + count = var.cassandra_node_count + connection { + host = element(sort(grid5000_deployment.cassandra_deployment.nodes), var.cassandra_node_count) + type = "ssh" + user = "root" + private_key = file("~/.ssh/id_rsa") + } + + provisioner "file" { + source = "../ansible" + destination = "/root/ansible" + } + + provisioner "remote-exec" { + inline = [ + "/root/ansible/ansible.sh", + ] + } +} + + +output "global_job_id" { + value = grid5000_job.reservation.id +} + +output "all_nodes" { + value = grid5000_job.reservation.assigned_nodes +} + +output "cassandra_job_id" { + value = grid5000_job.cassandra.id } -output "nodes" { +output "cassandra_nodes" { value = grid5000_job.cassandra.assigned_nodes } diff --git a/sysadmin/grid5000/cassandra/terraform/terraform.tf b/sysadmin/grid5000/cassandra/terraform/terraform.tf index f5df61d..f921e43 100644 --- a/sysadmin/grid5000/cassandra/terraform/terraform.tf +++ b/sysadmin/grid5000/cassandra/terraform/terraform.tf @@ -1,8 +1,12 @@ terraform { required_providers { + ansible = { + source = "habakke/ansible" + version = "~> 1.0.9" + } grid5000 = { source = "pmorillon/grid5000" version = "0.0.7" } } } diff --git a/sysadmin/grid5000/cassandra/terraform/variables.tf b/sysadmin/grid5000/cassandra/terraform/variables.tf new file mode 100644 index 0000000..16c444f --- /dev/null +++ b/sysadmin/grid5000/cassandra/terraform/variables.tf @@ -0,0 +1,41 @@ +variable "site" { + description = "the grid5000 site to use" + default = "rennes" + type = string +} + +variable "cluster" { + description = "the grid5000 cluster to use" + default = "parasilo" + type = string +} + +variable "total_node_count" { + description = "The total number of nodes to reserve" + default = "1" + type = number +} + +variable "cassandra_node_count" { + description = "The total number of cassandra nodes to install" + default = "1" + type = number +} + +variable "sleep_time" { + description = "the reservation duration" + default = "1h" + type = string +} + +variable "walltime" { + description = "the reservation duration" + default = "01:00:00" + type = string +} + +variable "cassandra_walltime" { + description = "the reservation duration" + default = "00:58:00" + type = string +}