Restructure roles

This commit is contained in:
hybris 2019-02-04 13:22:51 +01:00
parent 490cb5c3e6
commit 0183d6b307
9 changed files with 11 additions and 10 deletions

View file

@ -0,0 +1,14 @@
version: 1
config:
- type: physical
name: eth0
mac_address: {{ item.mac_address }}
subnets:
- type: static
address: {{ item.ipv6 }}/64
gateway: {{ network_default_gw }}
- type: nameserver
address:
- {{ network_dns }}
search:
- {{ network_domain }}

View file

@ -0,0 +1,19 @@
#cloud-config
users:
- name: {{ ansible_ssh_user }}
lock-passwd: false
sudo: ALL=(ALL) NOPASSWD:ALL
ssh_authorized_keys:
- {{ remote_user_ssh_pubkey }}
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 {{ ansible_ssh_user }}:{{ ansible_ssh_user }} /home/{{ ansible_ssh_user }}
path: /home/{{ ansible_ssh_user }}/cloud-init.sh
owner: {{ ansible_ssh_user }}:{{ ansible_ssh_user }}
permissions: '0744'
runcmd:
- [ '/home/{{ ansible_ssh_user }}/cloud-init.sh' ]

View file

@ -0,0 +1,49 @@
resource "libvirt_domain" "domain-{{ item.hostname }}" {
name = "{{ item.hostname }}"
memory = "{{ item.memory }}"
vcpu = "{{ item.vcpu }}"
cloudinit = "${libvirt_cloudinit_disk.cloud-init-{{ item.hostname }}.id}"
network_interface {
bridge = "{{ libvirt_network_bridge }}"
mac = "{{ item.mac_address }}"
}
boot_device {
dev = ["hd"]
}
disk {
volume_id = "${libvirt_volume.{{ item.hostname }}.id}"
}
graphics {
type = "spice"
listen_type = "address"
autoport = true
}
}
resource "libvirt_volume" "{{ item.hostname }}" {
name = "{{ item.hostname }}"
source = "{{ source_cloud_image_name }}"
pool = "{{ libvirt_storage_pool }}"
format = "qcow2"
}
resource "libvirt_cloudinit_disk" "cloud-init-{{ item.hostname }}" {
name = "cloud-init-{{ item.hostname }}.iso"
pool = "{{ libvirt_storage_pool }}"
user_data = "${data.template_file.user-data-{{ item.hostname }}.rendered}"
network_config = "${data.template_file.network-config-{{ item.hostname }}.rendered}"
}
data "template_file" "user-data-{{ item.hostname }}" {
template = "${file("${path.module}/{{ item.hostname }}.cloud_init.cfg")}"
}
data "template_file" "network-config-{{ item.hostname }}" {
template = "${file("${path.module}/{{ item.hostname }}.cloud_init_network.cfg")}"
}

View file

@ -0,0 +1,3 @@
provider "libvirt" {
uri = "qemu+ssh://[{{ libvirt_host }}]/system?socket=/var/run/libvirt/libvirt-sock"
}