Score:0

cloud-init seems to be ignoring write-files script

ng flag

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
SinaOwolabi avatar
ng flag
yaml is a pain. Wow
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.