Преглед на файлове

new deployment code

master
Markus Katharina Brechtel преди 4 години
родител
ревизия
090ecaef1e
променени са 8 файла, в които са добавени 60 реда и са изтрити 34 реда
  1. +5
    -3
      .gitignore
  2. +12
    -0
      Taskfile.yml
  3. +1
    -3
      common.yaml
  4. +19
    -0
      deploy.yaml
  5. +0
    -7
      etcd.tf
  6. +1
    -0
      inventory
  7. +22
    -2
      inventory.tf
  8. +0
    -19
      inventory_input.tf

+ 5
- 3
.gitignore Целия файл

@@ -1,5 +1,7 @@
.terraform
*.auto.tfvars
*.tfstate
*.tfstate.backup
terraform-info.json
provider_hetzner.auto.tfvars
inventory.json
terraform.tfstate
terraform.tfstate.backup
inventory.auto.tfvars.json

+ 12
- 0
Taskfile.yml Целия файл

@@ -0,0 +1,12 @@
version: '2'

tasks:
default:
cmds:
- ansible-playbook -i inventory -i inventory.json deploy.yaml
- terraform init
- terraform apply -auto-approve
- ansible-playbook -i inventory -i inventory.json common.yaml
wordpress:
cmds:
- ansible-playbook -i inventory -i inventory.json wordpress.yaml

+ 1
- 3
common.yaml Целия файл

@@ -1,8 +1,6 @@
---

- hosts:
- controllers
- nameservers
- hosts: vmst
remote_user: root
roles:
- role: common

+ 19
- 0
deploy.yaml Целия файл

@@ -0,0 +1,19 @@
---

- hosts: localhost
vars:
vm_hosts: "{
{% for hostname in groups.vms %}
{{hostname|to_json}}: {{
{
'provider': hostvars[hostname].provider,
'server_type': hostvars[hostname].server_type,
} | to_json }},
{% endfor %} }"
tasks:
- name: terraform inventory vars
copy:
content:
vm_hosts: "{{ vm_hosts }}"
groups: {}
dest: "{{playbook_dir}}/inventory.auto.tfvars.json"

+ 0
- 7
etcd.tf Целия файл

@@ -1,7 +0,0 @@
#terraform {
# backend "etcdv3" {
# endpoints = ["localhost:2379"]
# lock = true
# prefix = "testing/terraform-state/"
# }
#}

+ 1
- 0
inventory Целия файл

@@ -0,0 +1 @@
[vms]

ansible_inventory.tf → inventory.tf Целия файл

@@ -1,3 +1,23 @@
variable "vm_hosts" {
default = {
#"hostname.example.com" = {
# provider = "hetzner"
# groups = [ "testgroup" ]
# volumes = {
# data = { size = 32 }
# }
#}
}
}

variable "groups" {
default = {
#testgroup = {
# testvar1 = "bla"
#}
}
}

variable "ansible_inventory_filename" {
type = string
default = "inventory.json"
@@ -28,7 +48,7 @@ locals {
},{
for providername, provider in local.providers: "provider_${providername}" => {
hosts = {
for hostname, host in local.vm_hosts_with_groups:
for hostname, host in var.vm_hosts:
hostname => local.providers[host.provider].hostvars[hostname]
if host.provider == providername
}
@@ -43,7 +63,7 @@ output "ansible_inventory" {
value = local.ansible_inventory
}

resource "local_file" "foo" {
resource "local_file" "ansible_inventory" {
content = jsonencode(local.ansible_inventory)
filename = var.ansible_inventory_filename
file_permission = "0644"

+ 0
- 19
inventory_input.tf Целия файл

@@ -1,19 +0,0 @@
variable "vm_hosts" {
default = {
"controller.testing.thengo.net" = {
provider = "hetzner"
groups = [ "controllers" ]
#volumes = {
# data = { size = 32 }
#}
}
#"ns.testing.thengo.net" = { provider = "hetzner", groups = [ "nameservers" ] }
}
}

variable "groups" {
default = {
reverse_proxies = {
}
}
}

Loading…
Отказ
Запис