1
votes

In AWS OpsWorks, I'm using this community hostname cookbook. To set my hostname to append a domain to it.

Original FQDN: apple-pie.localdomain

node.default["set_fqdn"] = "*.example.com"
include_recipe 'hostname'

Changes to FQDN: apple-pie.localdomain.example.com

However, after about 10 mins, the hostname goes back to the original hostname without my domain append.

I've checked the OpsWorks lifecycle:

After a new instance finishes booting, AWS OpsWorks does the following:

  1. Runs the built-in Setup recipes.

  2. Runs any custom Setup recipes.

  3. Runs the built-in Deploy recipes.

  4. Runs any custom Deploy recipes.

And I'm running the recipe in my custom Deploy recipe, so it should be the last thing that runs. No idea why/how it gets reset to the original hostname.

Thanks!

1
Sounds like Amazon is changing the hostname... - sethvargo

1 Answers

2
votes

I figured it out. You're suppose to override the default template in Chef that AWS provides.

Extending AWS OpsWorks Configuration Files Using Custom Templates

So in my cookbook, I made a file called:

opsworks_stack_state_sync/templates/default/hosts.erb

Add the file looks like this:

# This file was generated by OpsWorks
# any manual changes will be removed on the next update.

# Set the hostname with proper format, the rest are aliases.
127.0.0.1 localhost localhost.example.com
127.0.1.1 <%= node[:opsworks][:instance][:hostname] %>.example.com <%= node[:opsworks][:instance][:hostname] %>

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

# OpsWorks Layer State
<% seen = [] -%>
<% node[:opsworks][:layers].each do |layer_name, layer_config| -%>
<% layer_config[:instances].each do |instance_name, instance_config| -%>
<% if !seen.include?(instance_name) && instance_config[:private_ip] -%>
<%= Resolv.getaddress(instance_config[:private_ip]) %> <%= instance_name %>
<% if instance_config[:ip] %>
<%= Resolv.getaddress(instance_config[:ip]) %> <%= instance_name %>-ext
<% end %>
<% seen << instance_name %>
<% end -%>
<% end -%>
<% end -%>

And that will set your hostname to apple-pie.example.com.