mode: 0755
path: "/usr/local/bin/vsphere-hostname.sh"
contents:
  inline: |
    #!/usr/bin/env bash
    set -e

    # only run if the hostname is not set
    test -f /etc/hostname && exit 0 || :

    if vm_name=$(/bin/vmtoolsd --cmd 'info-get guestinfo.hostname'); then
        /usr/bin/hostnamectl set-hostname --static ${vm_name}
    fi
