initial commit

This commit is contained in:
hybris 2019-01-22 13:10:16 +01:00
commit ee4a13c926
13 changed files with 571 additions and 0 deletions

View file

@ -0,0 +1,20 @@
#cloud-config
users:
- name: hybris
lock-passwd: false
passwd: $1$tG6Uv4$BPCIRF6RFuLrJ.lQO1GB8.
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
write_files:
- content: |
#!/bin/bash
# inet6_addr=$(ip a s | grep "inet6 2001:470:6d:22c:" | awk '{print substr($2,0)}')
sudo hostnamectl set-hostname {{ item.hostname }}
sudo ip -6 addr add {{ item.ipv6 }}/64 dev eth0
sudo chown -R hybris:hybris /home/hybris
path: /home/hybris/cloud-init.sh
owner: hybris:hybris
permissions: '0744'
runcmd:
- [ '/home/hybris/cloud-init.sh' ]

View file

@ -0,0 +1,55 @@
resource "libvirt_cloudinit_disk" "cloud-init-{{ item.hostname }}" {
name = "cloud-init-{{ item.hostname }}.iso"
pool = "kubernetes"
user_data = "${data.template_file.user-data-{{ item.hostname }}.rendered}"
}
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"
format = "qcow2"
}
resource "libvirt_domain" "domain-{{ item.hostname }}" {
name = "{{ item.hostname }}"
memory = "1024"
vcpu = 1
cloudinit = "${libvirt_cloudinit_disk.cloud-init-{{ item.hostname }}.id}"
console {
type = "pty"
target_port = "0"
target_type = "serial"
}
console {
type = "pty"
target_type = "virtio"
target_port = "1"
}
network_interface {
bridge = "home-lan"
mac = "{{ item.mac_address }}"
}
boot_device {
dev = ["hd"]
}
disk {
volume_id = "${libvirt_volume.centos-7-generic-{{ item.hostname }}.id}"
}
graphics {
type = "spice"
listen_type = "address"
autoport = true
}
}

View file

@ -0,0 +1,3 @@
provider "libvirt" {
uri = "qemu+ssh://[2001:470:6d:22c:1::1]/system?socket=/var/run/libvirt/libvirt-sock"
}

View file

@ -0,0 +1,67 @@
---
- name: install packages
yum:
name:
- libvirt-devel
- git
- gcc
- unzip
state: present
become: yes
- name: download and install terraform 0.11.11 release
unarchive:
src: https://releases.hashicorp.com/terraform/0.11.11/terraform_0.11.11_linux_amd64.zip
dest: /usr/local/bin
remote_src: yes
become: yes
- name: download and install golang 1.11.4 release
unarchive:
src: https://dl.google.com/go/go1.11.4.linux-amd64.tar.gz
dest: /usr/local
remote_src: yes
become: yes
- name: export path
lineinfile:
path: /etc/profile
regexp: '^export PATH=$PATH:/usr/local/go/bin'
line: 'export PATH=$PATH:/usr/local/go/bin'
become: yes
- name: go get terraform-provider-libvirt
shell: /usr/local/go/bin/go get github.com/dmacvicar/terraform-provider-libvirt
- name: go install terraform-provider-libvirt
shell: /usr/local/go/bin/go install
args:
chdir: /home/hybris/go/src/github.com/dmacvicar/terraform-provider-libvirt
- name: create terraform config directory
file:
path: /home/hybris/.terraform.d/
state: directory
- name: create terraform plugin directory
file:
path: /home/hybris/.terraform.d/plugins
state: directory
- name: install terraform-provider-libvirt
copy:
src: /home/hybris/go/bin/terraform-provider-libvirt
dest: /home/hybris/.terraform.d/plugins/terraform-provider-libvirt
mode: 0777
owner: hybris
remote_src: yes
- name: delete terraform directory
file:
path: /home/hybris/terraform
state: absent
- name: create terraform directory
file:
path: /home/hybris/terraform
state: directory