This commit is contained in:
hybris 2019-01-25 19:04:04 +01:00
parent e98c866057
commit 18f5d78a93
6 changed files with 64 additions and 101 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

@ -1,20 +1,19 @@
#cloud-config
users:
- name: {{ remote_user }}
- name: {{ ansible_ssh_user }}
lock-passwd: false
passwd: {{ remote_user_pass }}
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 {{ remote_user }}:{{ remote_user }} /home/{{ remote_user }}
path: /home/{{ remote_user }}/cloud-init.sh
owner: {{ remote_user }}:{{ remote_user }}
- 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/{{ remote_user }}/cloud-init.sh' ]
- [ '/home/{{ ansible_ssh_user }}/cloud-init.sh' ]

View file

@ -1,20 +1,3 @@
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}"
}
data "template_file" "user-data-{{ item.hostname }}" {
template = "${file("${path.module}/{{ item.hostname }}.cloud_init.cfg")}"
}
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 = "{{ item.memory }}"
@ -22,18 +5,6 @@ resource "libvirt_domain" "domain-{{ item.hostname }}" {
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 = "{{ libvirt_network_bridge }}"
mac = "{{ item.mac_address }}"
@ -52,4 +23,27 @@ resource "libvirt_domain" "domain-{{ item.hostname }}" {
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

@ -8,6 +8,7 @@
- absent
- directory
# TODO: make it actually download the image, lol (module:uri)
- name: "download qcow2 cloud image"
copy:
src: "/home/{{ ansible_ssh_user }}/images/{{ source_cloud_image_name }}"