Restructure roles
This commit is contained in:
parent
490cb5c3e6
commit
0183d6b307
9 changed files with 11 additions and 10 deletions
14
roles/terraform/templates/cloud-init-network.cfg.j2
Normal file
14
roles/terraform/templates/cloud-init-network.cfg.j2
Normal 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 }}
|
19
roles/terraform/templates/cloud-init.cfg.j2
Normal file
19
roles/terraform/templates/cloud-init.cfg.j2
Normal 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' ]
|
49
roles/terraform/templates/cloud-init.tf.j2
Normal file
49
roles/terraform/templates/cloud-init.tf.j2
Normal 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")}"
|
||||
}
|
||||
|
3
roles/terraform/templates/libvirt_provider.tf.j2
Normal file
3
roles/terraform/templates/libvirt_provider.tf.j2
Normal file
|
@ -0,0 +1,3 @@
|
|||
provider "libvirt" {
|
||||
uri = "qemu+ssh://[{{ libvirt_host }}]/system?socket=/var/run/libvirt/libvirt-sock"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue