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:

    local-hostname: ${hostname}
    instance-hostname: ${hostname}
      - content: |
          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
       -  /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
  • yaml is a pain. Wow Dec 27, 2021 at 21:19

1 Answer 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.