From 0482b34923638cf62dcc573029ff8ce9cdcee417 Mon Sep 17 00:00:00 2001 From: hybris Date: Tue, 22 Jan 2019 15:28:46 +0100 Subject: [PATCH] make everything more configurable --- 1-terraform.yml | 33 ++++++++++++++++++++--- 2-setup-kubernetes.yml | 4 +++ roles/kubernetes/tasks/main.yml | 18 +++++++++++++ roles/terraform/files/cloud-init.cfg.j2 | 4 +-- roles/terraform/files/cloud-init.tf.j2 | 18 ++++++------- roles/terraform/files/libvirt_provider.tf | 2 +- 6 files changed, 63 insertions(+), 16 deletions(-) diff --git a/1-terraform.yml b/1-terraform.yml index a5c5b4e..edd8da4 100644 --- a/1-terraform.yml +++ b/1-terraform.yml @@ -5,31 +5,55 @@ ########################################## ###### DEFINE YOUR MACHINES HERE vars: + # libvirt host vars + libvirt_host: [2001:470:6d:22c:1::1] + libvirt_storage_pool: kubernetes + libvirt_network_bridge: home-lan + + # ansible user vars + # python -c 'import crypt; print crypt.crypt("This is my Password", "$1$SomeSalt$")' + remote_user_pass: $1$tG6Uv4$BPCIRF6RFuLrJ.lQO1GB8. + remote_user_ssh_pubkey: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDXh0iMMtbTEhRSgIbgCunAuE+Q1iKycRVRBYWDCQ45xE8nHsg7K98fdv6LqQwkTqlojEHKp2/TPawk8V6w3MTgOHXi/WO9FyvhMjUcfdxTvny1z3Pj1j0NglKjyQ3t30snwOBYJiC2qDDtvRYNJs+Re/aSdVbygOHMf0UqCyP8DL7Tcj5sNPgnleEC7jE+YNbyDJo2KtNFXy3+AMbwa742D5Ygi5FqaBO090gVQfb3hbnZLw9CNSK7vjo7k5hJo8d1kcPDth1Vo12IDejL8Al3ArfGSy5IqYXs8Stj4YVRW+78AOpQZiInCaFybqjsGG+5tezrXHrxhjJPHuSCuXk9vxkcUk7aC5eSDqoCP7RTB+iQCPJ1ZvkVbaebExZGgHpD9t2Xo2bd/3BRagIxPTzKo9q4+qCCClhWR4iUSOr/YKAZBFDdoVWg2IMqbUHzvHX7TE7I8hbAdg6CpgwBoJm8OWmfjkDU6aYnF8z9l36VV7xjvvuYbOrhpCJ9LGFSfmG3wswo8OH4XyRSHd3y7qrSYIGujtymrzozXo2MrMU3Rj2bW5MIEZSxleIVje4PHWOfZwwn3hwvqM/nyknzfNwPCidTsP3Q2FwfBtZYo1cIXH41bzjs4Bxb8+KJqwTcerzB1pT4qsoPnoYW0fnZE7NHVNhfNx53LdctclFerHTLMw== hybris@sparks + + ## does this make sense?? + source_cloud_image_name: CentOS-7-x86_64-GenericCloud.qcow2 + source_cloud_image_url: https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud-1503.qcow2 + kubernetes: - hostname: k8s-master ipv6: 2001:470:6d:22c:42::1 mac_address: 52:54:00:b2:52:86 + memory: 5072 + vcpu: 2 - hostname: k8s-node-1 ipv6: 2001:470:6d:22c:42::10 mac_address: 52:54:00:52:b2:b2 + memory: 5072 + vcpu: 2 - hostname: k8s-node-2 ipv6: 2001:470:6d:22c:42::20 mac_address: 52:54:00:52:2f:86 + memory: 5072 + vcpu: 2 - hostname: k8s-node-3 ipv6: 2001:470:6d:22c:42::30 mac_address: 52:54:00:52:2f:b2 + memory: 5072 + vcpu: 2 - hostname: k8s-node-4 ipv6: 2001:470:6d:22c:42::40 mac_address: 52:54:00:b2:2f:86 + memory: 5072 + vcpu: 2 ###### ########################################## tasks: - # - name: download qcow2 cloud image - # uri: - # url: - # dest: + - name: download qcow2 cloud image + uri: + url: {{ source_cloud_image_url }} + dest: /home/{{ remote_user }}/terraform/{{ source_cloud_image_name }} - name: create vm definitions template: @@ -71,3 +95,4 @@ shell: terraform apply "cloud-init-plan" args: chdir: /home/{{ remote_user }}/terraform +[] \ No newline at end of file diff --git a/2-setup-kubernetes.yml b/2-setup-kubernetes.yml index e762dc8..55e038c 100644 --- a/2-setup-kubernetes.yml +++ b/2-setup-kubernetes.yml @@ -3,6 +3,10 @@ remote_user: hybris become: yes + vars: + # rename this to something with sense + network_default_gw: 2001:470:6d:22c::1 + roles: - dns - proxy diff --git a/roles/kubernetes/tasks/main.yml b/roles/kubernetes/tasks/main.yml index 5546fee..918d274 100644 --- a/roles/kubernetes/tasks/main.yml +++ b/roles/kubernetes/tasks/main.yml @@ -1,4 +1,22 @@ --- +####################### +#### NETWORK TASKS #### +####################### + + - name: set static ipv6 for hosts + lineinfile: + path: /etc/sysconfig/network-scripts/ifcfg-eth0 + line: {{ item.line }} + regexp: {{ item.regexp }} + with_items: + - { regexp: "^IPV6INIT=", line: "IPV6INIT=yes" } + - { regexp: "^IPV6AUTOCONF=", line: "IPV6AUTOCONF=no" } + - { regexp: "^IPV6ADDR=", line: "IPV6ADDR={{ host_ipv6 }}"} + - { regexp: "^IPV6_DEFAULTGW=", line: "IPV6_DEFAULTGW={{ network_default_gw }}"} + + - name: reboot + reboot: + ######################## #### FIREWALL TASKS #### ######################## diff --git a/roles/terraform/files/cloud-init.cfg.j2 b/roles/terraform/files/cloud-init.cfg.j2 index c93397b..ea290a0 100644 --- a/roles/terraform/files/cloud-init.cfg.j2 +++ b/roles/terraform/files/cloud-init.cfg.j2 @@ -2,10 +2,10 @@ users: - name: {{ remote_user }} lock-passwd: false - passwd: $1$tG6Uv4$BPCIRF6RFuLrJ.lQO1GB8. + passwd: {{ remote_user_pass }} sudo: ALL=(ALL) NOPASSWD:ALL ssh_authorized_keys: - - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDXh0iMMtbTEhRSgIbgCunAuE+Q1iKycRVRBYWDCQ45xE8nHsg7K98fdv6LqQwkTqlojEHKp2/TPawk8V6w3MTgOHXi/WO9FyvhMjUcfdxTvny1z3Pj1j0NglKjyQ3t30snwOBYJiC2qDDtvRYNJs+Re/aSdVbygOHMf0UqCyP8DL7Tcj5sNPgnleEC7jE+YNbyDJo2KtNFXy3+AMbwa742D5Ygi5FqaBO090gVQfb3hbnZLw9CNSK7vjo7k5hJo8d1kcPDth1Vo12IDejL8Al3ArfGSy5IqYXs8Stj4YVRW+78AOpQZiInCaFybqjsGG+5tezrXHrxhjJPHuSCuXk9vxkcUk7aC5eSDqoCP7RTB+iQCPJ1ZvkVbaebExZGgHpD9t2Xo2bd/3BRagIxPTzKo9q4+qCCClhWR4iUSOr/YKAZBFDdoVWg2IMqbUHzvHX7TE7I8hbAdg6CpgwBoJm8OWmfjkDU6aYnF8z9l36VV7xjvvuYbOrhpCJ9LGFSfmG3wswo8OH4XyRSHd3y7qrSYIGujtymrzozXo2MrMU3Rj2bW5MIEZSxleIVje4PHWOfZwwn3hwvqM/nyknzfNwPCidTsP3Q2FwfBtZYo1cIXH41bzjs4Bxb8+KJqwTcerzB1pT4qsoPnoYW0fnZE7NHVNhfNx53LdctclFerHTLMw== hybris@sparks + - {{ remote_user_ssh_pubkey }} write_files: - content: | #!/bin/bash diff --git a/roles/terraform/files/cloud-init.tf.j2 b/roles/terraform/files/cloud-init.tf.j2 index 95e8d1f..107871f 100644 --- a/roles/terraform/files/cloud-init.tf.j2 +++ b/roles/terraform/files/cloud-init.tf.j2 @@ -1,6 +1,6 @@ resource "libvirt_cloudinit_disk" "cloud-init-{{ item.hostname }}" { name = "cloud-init-{{ item.hostname }}.iso" - pool = "kubernetes" + pool = "{{ libvirt_storage_pool }}" user_data = "${data.template_file.user-data-{{ item.hostname }}.rendered}" } @@ -8,17 +8,17 @@ data "template_file" "user-data-{{ item.hostname }}" { template = "${file("${path.module}/{{ item.hostname }}.cloud_init.cfg")}" } -resource "libvirt_volume" "centos-7-generic-{{ item.hostname }}" { - name = "centos-7-generic-{{ item.hostname }}" - source = "CentOS-7-x86_64-GenericCloud.qcow2" - pool = "kubernetes" +resource "libvirt_volume" "{{ item.hostname }}" { + name = "{{ item.hostname }}" + source = "{{ source_cloud_image_name }}" + pool = "{{ libvirt_storage_pool }}" format = "qcow2" } resource "libvirt_domain" "domain-{{ item.hostname }}" { name = "{{ item.hostname }}" - memory = "1024" - vcpu = 1 + memory = "{{ item.memory }}" + vcpu = "{{ item.vcpu }}" cloudinit = "${libvirt_cloudinit_disk.cloud-init-{{ item.hostname }}.id}" @@ -35,7 +35,7 @@ resource "libvirt_domain" "domain-{{ item.hostname }}" { } network_interface { - bridge = "home-lan" + bridge = "{{ libvirt_network_bridge }}" mac = "{{ item.mac_address }}" } @@ -44,7 +44,7 @@ resource "libvirt_domain" "domain-{{ item.hostname }}" { } disk { - volume_id = "${libvirt_volume.centos-7-generic-{{ item.hostname }}.id}" + volume_id = "${libvirt_volume.{{ item.hostname }}.id}" } graphics { diff --git a/roles/terraform/files/libvirt_provider.tf b/roles/terraform/files/libvirt_provider.tf index 6e71b7c..19e88d8 100644 --- a/roles/terraform/files/libvirt_provider.tf +++ b/roles/terraform/files/libvirt_provider.tf @@ -1,3 +1,3 @@ provider "libvirt" { - uri = "qemu+ssh://[2001:470:6d:22c:1::1]/system?socket=/var/run/libvirt/libvirt-sock" + uri = "qemu+ssh://{{ libvirt_host }}/system?socket=/var/run/libvirt/libvirt-sock" } \ No newline at end of file