0

H!

I am trying to configure VMs with cloud-init, using the terraform Libvirt provider. For some reason I don't understand, setting hostname works, but writing and running a script for additional configuration is completely ignored. Would appreciate if anyone can explain what I'm doing incorrectly. My yaml:

    #cloud-config
    local-hostname: ${hostname}
    instance-hostname: ${hostname}
    write_files:
      - content: |
          #/bin/bash
          hostnamectl set-hostname ${hostname}
          NET_INT=$(ip link | awk -F: '$0 !~ "lo|vir|wl|^[^0-9]"{print $2;getline}')
          nmcli con mod $NET_INT ipv4.dns "X.X.X.X"
          nmcli con mod $NET_INT ipv4.dns-search "dom.internal"
          ipa-client-install --hostname=${hostname} \
          --server=XXX.services.dom.internal \
          --mkhomedir --domain=services.dom.internal \
          --realm=SERVICES.DOM.INTERNAL --no-ntp --principal=someguy \
          --password=XXXXX --enable-dns-updates --unattended
          ipa-client-automount --unattended
        path: /tmp/setup.sh
        permissions: '0755'
        owner: root
     runcmd:
       -  /tmp/setup.sh

(hopefully) relevant .tf bits:

data "template_file" "custom_config" {
   template = file("${path.module}/meta_data.yaml")

   vars = {
      hostname = "${var.vm_name}.dom.internal"
   }
}

resource "libvirt_cloudinit_disk" "commoninit" {
   name = "commoninit.iso"
   meta_data =  data.template_file.custom_config.rendered

   pool = "pool"
}

resource "libvirt_domain" "centos8_vm" {

  name = "${var.vm_name}"
  cloudinit = libvirt_cloudinit_disk.commoninit.id
  qemu_agent = true
Unpossible
  • 249
  • 1
  • 7
  • 20

1 Answers1

1

Correct syntax for Shebang is #!interpreter [optional-arg]. This line of code tells the system which program to run this script.

So the first line of your script should be #!/bin/bash, or it'll be treated as regular comments.

jam2
  • 26
  • 1