Generate LXD tfvars instead of environment variable

This commit is contained in:
Khue Doan
2021-04-21 23:28:54 +07:00
parent 147dfd57ef
commit 613fb33959
4 changed files with 22 additions and 4 deletions

2
.gitignore vendored
View File

@ -4,5 +4,7 @@ metal/secrets/
*.log *.log
.terraform* .terraform*
terraform.tfvars
kube_config.yaml kube_config.yaml
private.pem
terraform.tfstate* terraform.tfstate*

View File

@ -21,6 +21,14 @@ terraform {
provider "lxd" { provider "lxd" {
generate_client_certificates = true generate_client_certificates = true
accept_remote_certificate = true accept_remote_certificate = true
lxd_remote {
name = "homelab"
scheme = "https"
address = var.lxd_address
password = var.lxd_password
default = true
}
} }
provider "rke" { provider "rke" {

View File

@ -0,0 +1,7 @@
variable "lxd_address" {
description = "LXD cluster address, should be generated automatically from metal"
}
variable "lxd_password" {
description = "Password to connect to LXD cluster, should be generated automatically from metal"
}

View File

@ -35,18 +35,19 @@
creates: /var/snap/lxd/common/lxd/server.crt creates: /var/snap/lxd/common/lxd/server.crt
when: inventory_hostname != groups['metal'][0] when: inventory_hostname != groups['metal'][0]
# TODO optimize: use template for tfvars
- name: Add LXD server to environment variables - name: Add LXD server to environment variables
lineinfile: lineinfile:
path: "{{ playbook_dir }}/secrets/env" path: "{{ playbook_dir }}/../infra/platform/terraform.tfvars"
line: "LXD_ADDR={{ hostvars[groups['metal'][0]]['ansible_host'] }}" line: "lxd_address = \"{{ hostvars[groups['metal'][0]]['ansible_host'] }}\""
create: yes create: yes
delegate_to: localhost delegate_to: localhost
run_once: yes run_once: yes
- name: Add LXD password to environment variables - name: Add LXD password to environment variables
lineinfile: lineinfile:
path: "{{ playbook_dir }}/secrets/env" path: "{{ playbook_dir }}/../infra/platform/terraform.tfvars"
line: "LXD_PASSWORD={{ lxd_password }}" line: "lxd_password = \"{{ lxd_password }}\""
create: yes create: yes
delegate_to: localhost delegate_to: localhost
run_once: yes run_once: yes