Setting keys and password with cloud-init working.

ansible-test
shnee 4 years ago
parent b126da8acf
commit af17823d68

@ -8,3 +8,10 @@ libvirt provider depends on mkisofs
security_driver = none for ubuntu host, link github issue. security_driver = none for ubuntu host, link github issue.
https://github.com/dmacvicar/terraform-provider-libvirt/issues/546 https://github.com/dmacvicar/terraform-provider-libvirt/issues/546
Other
----------------------------------------
Create a password hash.
```shell
python3 -c 'import crypt; print(crypt.crypt("test", crypt.mksalt(crypt.METHOD_SHA512)))'
```

@ -1,20 +1,28 @@
#cloud-config #cloud-config
# vim: syntax=yaml # vim: syntax=yaml
#
# *********************** users:
# ---- for more examples look at: ------ - name: admin
# ---> https://cloudinit.readthedocs.io/en/latest/topics/examples.html # If we don't supress the user group then cloud init will fail because there
# ****************************** # is allready an admin group in the ubuntu base image.
# no_user_group: true
# This is the configuration syntax that the write_files module groups: users, admin, sudo
# will know how to understand. encoding can be given b64 or gzip or (gz+b64). shell: /usr/bin/bash
# The content will be decoded accordingly and then written to the path that is sudo: ALL=(ALL) NOPASSWD:ALL
# provided. ssh_authorized_keys:
# - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDfDcjMFmWd6qy9KIlnIHNbEfeNLHC885UUH3jGwESmMTpFfPUn01t9hq5GGaFDrBR55VgdKebAv2JSVl209+r3tE5XxUX5/s2Pu3o2283PiZhA+D18skL7fzaolygOY8mxi9CZSDFia//lLbqT/OE45VGahVBRtda4gmjrade0XRKqjJUCkIo6huG9Ub6yP4gFtFU/C1rRvQo0hqT/imsMYU0Q5XzrKVWv3CpzA7EIQq8llU0fRGMuXWYYOXznPeqqf5BTbWhMWUXVS0o7Cz+zvbxwq1dOR1qHbJ8Vrkt30Cz5QEd159dIM3LHCtOHnveeOpkFo0RqkhQdpZM+2cKzESvivGNGP9h+PrSjcveADxVwDHcxguumUyM012M3yR8cK9KY+GqW5jPdAs13yXGTG4OWiQKeKEgX910l/FndhQi0tSpSEhIlfcEpa3k3P8RrhKJbwiRgR7Qvus4R/KU+lxKOiOr4RKyPQJobC0i0/bvqkw+UHWp4U0Hqivjsb6k= admin
# Note: Content strings here are truncated for example purposes. - name: root
ssh_pwauth: True ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDfDcjMFmWd6qy9KIlnIHNbEfeNLHC885UUH3jGwESmMTpFfPUn01t9hq5GGaFDrBR55VgdKebAv2JSVl209+r3tE5XxUX5/s2Pu3o2283PiZhA+D18skL7fzaolygOY8mxi9CZSDFia//lLbqT/OE45VGahVBRtda4gmjrade0XRKqjJUCkIo6huG9Ub6yP4gFtFU/C1rRvQo0hqT/imsMYU0Q5XzrKVWv3CpzA7EIQq8llU0fRGMuXWYYOXznPeqqf5BTbWhMWUXVS0o7Cz+zvbxwq1dOR1qHbJ8Vrkt30Cz5QEd159dIM3LHCtOHnveeOpkFo0RqkhQdpZM+2cKzESvivGNGP9h+PrSjcveADxVwDHcxguumUyM012M3yR8cK9KY+GqW5jPdAs13yXGTG4OWiQKeKEgX910l/FndhQi0tSpSEhIlfcEpa3k3P8RrhKJbwiRgR7Qvus4R/KU+lxKOiOr4RKyPQJobC0i0/bvqkw+UHWp4U0Hqivjsb6k= admin
ssh_pwauth: true
disable_root: false
chpasswd: chpasswd:
list: | list:
root:terraform-libvirt-linux expire: false
expire: False
# Use this when it's determined that we need a bigger disk image.
# This must be used in conjuction with 'size' in 'libvirt_volume'
# growpart:
# mode: auto
# devices: ['/']

@ -1,7 +1,9 @@
terraform { terraform {
required_version = ">= 0.13"
required_providers { required_providers {
libvirt = { libvirt = {
source = "dmacvicar/libvirt" source = "dmacvicar/libvirt"
version = "0.6.11"
} }
} }
} }
@ -16,6 +18,8 @@ resource "libvirt_pool" "images" {
path = var.disk-image-dir path = var.disk-image-dir
} }
# Add 'size' when we need more space. It must be used in conjuction with
# 'growpart' in cloud-init as well.
resource "libvirt_volume" "master-image" { resource "libvirt_volume" "master-image" {
name = "k8s-tf-master" name = "k8s-tf-master"
pool = libvirt_pool.images.name pool = libvirt_pool.images.name
@ -39,10 +43,6 @@ data "template_file" "network_config" {
template = file("${path.module}/network_config.cfg") template = file("${path.module}/network_config.cfg")
} }
# for more info about paramater check this out
# https://github.com/dmacvicar/terraform-provider-libvirt/blob/master/website/docs/r/cloudinit.html.markdown
# Use CloudInit to add our ssh-key to the instance
# you can add also meta_data field
resource "libvirt_cloudinit_disk" "commoninit" { resource "libvirt_cloudinit_disk" "commoninit" {
name = "commoninit.images" name = "commoninit.images"
user_data = data.template_file.user_data.rendered user_data = data.template_file.user_data.rendered

Loading…
Cancel
Save