Well it works

This commit is contained in:
2024-01-27 23:26:11 +03:00
commit f8e6ed30d3
11 changed files with 223 additions and 0 deletions

11
terraform/ceph-disks.tf Normal file
View File

@@ -0,0 +1,11 @@
resource "lxd_volume" "ceph-osd-vol" {
pool = "default"
project = lxd_project.cephproject.name
name = format("ceph-osd-%d", count.index + 1)
count = 4
content_type = "block"
config = {
size = "10GiB"
}
}

View File

@@ -0,0 +1,12 @@
# generate inventory file for Ansible
resource "local_file" "ansible_inventory" {
content = templatefile(
"hosts.j2",
{
cephmons = {for key, value in lxd_instance.ceph-mon : value.name => value.ipv4_address }
cephosds = {for key, value in lxd_instance.ceph-osd : value.name => value.ipv4_address }
jumphost = var.ansible_jumphost
}
)
filename = "../data/inventory"
}

12
terraform/ceph-net.tf Normal file
View File

@@ -0,0 +1,12 @@
resource "lxd_network" "cephnet" {
# project = lxd_project.cephproject.name
name = "cephnet"
type = "bridge"
config = {
"ipv4.address" = "10.99.99.1/24"
"ipv4.nat" = "true"
"ipv6.address" = "fd42:474b:622d:259d::1/64"
"ipv6.nat" = "true"
}
}

92
terraform/ceph-vm.tf Normal file
View File

@@ -0,0 +1,92 @@
### ceph-mon
resource "lxd_instance" "ceph-mon" {
name = format("ceph-mon-%d", count.index + 1)
count = 4
type = "virtual-machine"
image = "ubuntu:jammy"
project = lxd_project.cephproject.name
profiles = ["default", "${lxd_profile.cephprofile.name}"]
config = {
"boot.autostart" = false
}
device {
name = "eth0"
type = "nic"
properties = {
nictype = "bridged"
parent = "${lxd_network.cephnet.name}"
"ipv4.address" = format("10.99.99.%d", count.index + 10)
}
}
limits = {
cpu = 2
memory = "4GiB"
}
execs = {
"shell_cmd" = {
command = ["/bin/sh", "-c", "echo $PUB_KEY | tee /root/.ssh/id_ed25519.pub /root/.ssh/authorized_keys ; echo \"$PRIV_KEY\" > /root/.ssh/id_ed25519 ; chmod 600 /root/.ssh/*"]
environment = {
"PUB_KEY" = file("../data/ceph_key.pub")
"PRIV_KEY" = file("../data/ceph_key")
}
}
}
}
### ceph-osd
resource "lxd_instance" "ceph-osd" {
name = format("ceph-osd-%d", count.index + 1)
count = 4
type = "virtual-machine"
image = "ubuntu:jammy"
project = lxd_project.cephproject.name
profiles = ["default", "${lxd_profile.cephprofile.name}"]
config = {
"boot.autostart" = false
}
device {
name = "eth0"
type = "nic"
properties = {
nictype = "bridged"
parent = "${lxd_network.cephnet.name}"
"ipv4.address" = format("10.99.99.%d", count.index + 20)
}
}
device {
name = format("ceph-osd-%d", count.index + 1)
type = "disk"
properties = {
source = format("ceph-osd-%d", count.index + 1)
pool = "default"
}
}
limits = {
cpu = 2
memory = "4GiB"
}
execs = {
"shell_cmd" = {
command = ["/bin/sh", "-c", "echo $PUB_KEY | tee /root/.ssh/id_ed25519.pub /root/.ssh/authorized_keys ; echo -e $PRIV_KEY > /root/.ssh/id_ed25519 ; chmod 600 /root/.ssh/*"]
environment = {
"PUB_KEY" = file("../data/ceph_key.pub")
"PRIV_KEY" = file("../data/ceph_key")
}
}
}
}

9
terraform/hosts.j2 Normal file
View File

@@ -0,0 +1,9 @@
[ceph-mon]
%{ for name, ip in cephmons ~}
${name} ansible_ssh_host=${ip} ansible_ssh_common_args='-J ${jumphost} -oStrictHostKeyChecking=no -i ../data/ceph_key' ansible_ssh_user='root'
%{ endfor ~}
[ceph-osd]
%{ for name, ip in cephosds ~}
${name} ansible_ssh_host=${ip} ansible_ssh_common_args='-J ${jumphost} -oStrictHostKeyChecking=no -i ../data/ceph_key' ansible_ssh_user='root'
%{ endfor ~}

43
terraform/init.tf Normal file
View File

@@ -0,0 +1,43 @@
terraform {
required_providers {
lxd = {
source = "terraform-lxd/lxd"
}
}
}
resource "lxd_project" "cephproject" {
name = "ceph"
description = "Terraform provider example project"
config = {
"features.storage.volumes" = false
"features.images" = false
"features.profiles" = false
"features.storage.buckets" = false
"features.networks" = true
}
}
resource "lxd_profile" "cephprofile" {
name = "cephprofile"
device {
name = "eth0"
type = "nic"
properties = {
nictype = "bridged"
parent = "${lxd_network.cephnet.name}"
}
}
device {
type = "disk"
name = "root"
properties = {
pool = "default"
path = "/"
}
}
}

View File

@@ -0,0 +1,2 @@
ansible_jumphost = "selded"
ceph_subnet = "10.99.99"