Merge branch 'fix_tags' into 'main'

remove tags from deployement

See merge request ataxya/tsunami!2
This commit is contained in:
Ataxya 2022-07-04 22:34:31 +00:00
commit db27c24ddd
3 changed files with 38 additions and 15 deletions

View File

@ -1,18 +1,32 @@
# Tsunami
**Netbox + XO + Terraform + Ansible = The best deployment kit**
How to run:<br>
cp passwd.auto.tfvars.example passwd.auto.tfvars<br>
replace all variable to match your infrastructure
## Configuration
edit cloud_network_config.tftpl to replace eth0 (to be changed)
[Install terraform](https://www.terraform.io/downloads)
create a prefix with IP you want to use on netbox <br>
edit variables.auto.tfvars
replace your variables:
```bash
# copy password template
cp passwd.auto.tfvars.example passwd.auto.tfvars
# edit with your infra passwords
nano passwd.auto.tfvars
# set your template vm network interface
nano cloud_network_config.tftpl
# create a prefix with IP you want to use on netbox, and set your vm variables
nano variables.auto.tfvars
```
You can add your playbook in the folder playbooks/ and use them in variables.auto.tfvars
then
## Run
terraform init<br>
terraform plan<br>
```bash
terraform init
terraform plan
terraform apply
```

15
main.tf
View File

@ -31,7 +31,7 @@ data "xenorchestra_template" "template" {
}
resource "xenorchestra_vm" "bar" {
resource "xenorchestra_vm" "vm_deployed" {
memory_max = var.ram * 1024 * 1024 * 1024
cpus = var.cpu
cloud_config = templatefile("cloud_config.tftpl", {
@ -58,10 +58,7 @@ resource "xenorchestra_vm" "bar" {
size = var.disk_size * 1024 * 1024 * 1024
}
tags = [
"Debian",
"Best Distro",
]
tags = var.vm_tags
// Override the default create timeout from 5 mins to 20.
timeouts {
@ -72,6 +69,8 @@ resource "xenorchestra_vm" "bar" {
# Generate inventory file
resource "local_file" "inventory" {
count = var.playbook != "" ? 1 : 0
filename = "inventory"
content = <<EOF
[all]
@ -80,12 +79,16 @@ EOF
}
resource "time_sleep" "wait_30_seconds" {
depends_on = [xenorchestra_vm.bar]
count = var.playbook != "" ? 1 : 0
depends_on = [xenorchestra_vm.vm_deployed]
create_duration = "30s"
}
resource "null_resource" "run-ansible" {
count = var.playbook != "" ? 1 : 0
provisioner "local-exec" {
command = "ansible-playbook -D -i inventory playbooks/${var.playbook} "
environment = {

6
var.tf
View File

@ -68,6 +68,7 @@ variable "template" {
variable "playbook" {
type = string
default = ""
}
variable "cpu" {
@ -93,3 +94,8 @@ variable "disk_size" {
variable "ssh_keys" {
type = string
}
variable "vm_tags" {
type = list
default = []
}