Mark Tickner
Mark Tickner

Reputation: 1053

How do I have hostnames with full stop in Openstack Heat templates?

I am trying to set the hostname to be the full DNS name of a server, but if I include a full stop it seems to be cut from the end.

This is how I am setting the hostname:

properties:
      name: sample-name.domain.com

However, this gives a hostname of sample-name. The full name shows up correctly in the Instances list.

Upvotes: 0

Views: 790

Answers (2)

Mark Tickner
Mark Tickner

Reputation: 1053

This was the overall solution I used, based on @Tejaswi's:

user_data:
  #!/bin/bash -v
  sudo echo "127.0.0.1 sample-name.domain.com" >> /etc/hosts
  sudo hostname sample-name.domain.com
  sudo echo sample-name.domain.com > /etc/hostname
  sudo sed -i 's/preserve_hostname: false/preserve_hostname: true/g' /etc/cloud/cloud.cfg

I have also updated the /etc/hosts file, as well as enabling the preserve_hostname cloud-init property so that it doesn't reset on every restart.

Upvotes: 0

Tejaswi
Tejaswi

Reputation: 264

I looked into the /var/log/cloud-init.log and I see that the hostname is set to "sample-name" irrespective of whether you set the name to "sample-name.domain.com" or "sample-name" in the properties.

So, we can set the hostname using "user_data" in heat template as below:

user_data:
            #!/bin/bash
            sudo bash -c "echo 'sample-name.domain.com' > /etc/hostname"
            sudo bash -c "hostname sample-name.domain.com"

Upvotes: 1

Related Questions