Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hostname doesn't persist after reboot on EC2 rhel7 #47

Closed
fletchowns opened this issue Sep 10, 2016 · 12 comments
Closed

Hostname doesn't persist after reboot on EC2 rhel7 #47

fletchowns opened this issue Sep 10, 2016 · 12 comments
Assignees

Comments

@fletchowns
Copy link

[ec2-user@my-machine ~]$ sudo reboot
Connection to my-machine.myorg.com closed by remote host.
Connection to my-machine.myorg.com closed.
$ ssh my-machine.veevaalign.com
[ec2-user@ip-10-0-238-60 ~]$ hostname -f
ip-10-0-238-60.us-west-1.compute.internal

This was with the Redhat 7.2 AMI on AWS. Seems as though there might be some special considerations for rhel7 on EC2: https://aws.amazon.com/premiumsupport/knowledge-center/linux-static-hostname-rhel7-centos7/

@fletchowns
Copy link
Author

fletchowns commented Sep 10, 2016

The search_file_replace_line for /etc/sysconfig/network also doesn't seem to work correctly since there's no HOSTNAME line in there to begin with:

[ec2-user@my-machine ~]$ cat /etc/sysconfig/network
NETWORKING=yes
NOZEROCONF=yes

edit: Nevermind...it seems to skip that ruby_block anyways because of the platform_version < 7.0 conditional. Should it be like that?

@flaccid flaccid self-assigned this Sep 10, 2016
@flaccid flaccid added the bug label Sep 10, 2016
@flaccid
Copy link
Contributor

flaccid commented Sep 10, 2016

@fletchowns DHCP could generally still be a problem in terms of persisting a hostname. I think the main problem here though is Red Hat's lack of documentation for /etc/sysconfig/network in RHEL 7 - I followed https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Networking_Guide/sec_Configuring_Host_Names_Using_hostnamectl.html which is why at the moment that file is not updated.

@fletchowns
Copy link
Author

Right on, makes sense.

For now I just wanted to get it working so I tried:

file "/etc/sysconfig/network" do
    mode "0644"
    content "NETWORKING=yes\nNOZEROCONF=yes\nHOSTNAME=#{Chef::Config[:node_name]}.#{node["system"]["domain_name"]}"
end

I could see it make the change in my converge log:

         * file[/etc/sysconfig/network] action create
           - update content in file /etc/sysconfig/network from 75cf7f to 410a7b
           --- /etc/sysconfig/network   2016-03-01 18:38:53.652000000 -0500
           +++ /etc/sysconfig/.chef-network20160910-9434-nth1fn 2016-09-10 17:08:22.338515667 -0400
           @@ -1,3 +1,4 @@
            NETWORKING=yes
            NOZEROCONF=yes
           +HOSTNAME=my-machine.myorg.com

I didn't see anything else touching /etc/sysconfig/network in the converge log, but after the converge completed that file was back to missing HOSTNAME. Am I missing a step?

@flaccid
Copy link
Contributor

flaccid commented Sep 10, 2016

I would not be surprised if that is a DHCP renew doing that. As far as I can see HOSTNAME in this file is basically deprecated due to using systemd. I also would not honey badger that file with the file resource. I've spun up an EC2 instance now and will look at the minimum we should do.

The other general issue here is overlap with cloud-init. These modules are enabled in /etc/cloud/cloud.cfg:

 - set_hostname
 - update_hostname
 - update_etc_hosts

@flaccid
Copy link
Contributor

flaccid commented Sep 10, 2016

As far as I can see, cloud-init only does hostnamectl and updates /etc/hostname.
NetworkManager with a resident dhclient is getting leases like, e.g /var/lib/NetworkManager/dhclient-5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03-eth0.lease:

lease {
  interface "eth0";
  fixed-address 172.31.21.212;
  option subnet-mask 255.255.240.0;
  option routers 172.31.16.1;
  option dhcp-lease-time 3600;
  option dhcp-message-type 5;
  option domain-name-servers 172.31.0.2;
  option dhcp-server-identifier 172.31.16.1;
  option interface-mtu 9001;
  option broadcast-address 172.31.31.255;
  option host-name "ip-172-31-21-212";
  option domain-name "ap-southeast-2.compute.internal";
  renew 6 2016/09/10 22:40:13;
  rebind 6 2016/09/10 23:04:43;
  expire 6 2016/09/10 23:12:13;
}

@flaccid
Copy link
Contributor

flaccid commented Sep 10, 2016

Not exactly having much like. Trying everything and still not persisting. This includes:

sudo nmcli con modify 'System eth0' ipv4.dhcp-hostname shelly.rancher.cloud ipv6.dhcp-hostname shelly.rancher.cloud
sudo nmcli con modify 'System eth0' ipv4.dhcp-send-hostname no
sudo nmcli general hostname shelly.rancher.cloud
sudo systemctl restart systemd-hostnamed

@flaccid
Copy link
Contributor

flaccid commented Sep 10, 2016

Ok it does look like cloud-init's preserve_hostname: true does help. Will analyse the code more.

@fletchowns
Copy link
Author

Thank you for looking at this, really appreciate it!

@flaccid
Copy link
Contributor

flaccid commented Sep 11, 2016

@fletchowns no worries - would you be around next couple of hours to test new provider file before I commit and push?

@fletchowns
Copy link
Author

@flaccid yup definitely, I'll be online and available for the next 8 hours or so

@flaccid
Copy link
Contributor

flaccid commented Sep 11, 2016

Ok great! I have emailed you this working copy I'm playing with atm. I'm also on freenode IRC as flaccid. Let's see if we can get it nice for a merge and then new release.

flaccid added a commit that referenced this issue Sep 11, 2016
- always set HOSTNAME in /etc/sysconfig/network if the config file exists
- do not run domainname if the domainname is already as desired
- configure preserve_hostname with cloud-init if cloud-init is installed
- update hostname with nmcli if installed
- restart systemd-hostnamed if enabled
@flaccid
Copy link
Contributor

flaccid commented Sep 11, 2016

@flaccid flaccid closed this as completed Sep 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants