diff --git a/CHANGELOG.md b/CHANGELOG.md index aa8f85ff3..0b229ecd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,7 @@ BUG FIXES: - guests/redhat: NFS setup should use systemd for RH7+ [GH-4228] - guests/redhat: Detect RHEL 7 (and CentOS) and install Docker properly. [GH-4402] - guests/redhat: Configuring networks on EL7 works. [GH-4195] + - guests/redhat: Setting hostname on EL7 works. [GH-4352] - guests/smartos: Use `pfexec` for rsync. [GH-4274] - guests/windows: Reboot after hostname change. [GH-3987] - hosts/arch: NFS works with latest versions. [GH-4224] diff --git a/plugins/guests/redhat/cap/change_host_name.rb b/plugins/guests/redhat/cap/change_host_name.rb index 2bad4c9a0..f88cbcdad 100644 --- a/plugins/guests/redhat/cap/change_host_name.rb +++ b/plugins/guests/redhat/cap/change_host_name.rb @@ -3,7 +3,16 @@ module VagrantPlugins module Cap class ChangeHostName def self.change_host_name(machine, name) - new(machine, name).change! + case machine.guest.capability("flavor") + when :rhel_7 + change_host_name_rhel7(machine, name) + else + new(machine, name).change! + end + end + + def self.change_host_name_rhel7(machine, name) + machine.communicate.sudo("homenamectl set-hostname #{name}") end attr_reader :machine, :new_hostname diff --git a/test/unit/plugins/guests/redhat/cap/change_host_name_test.rb b/test/unit/plugins/guests/redhat/cap/change_host_name_test.rb index 663cfa298..558bb5983 100644 --- a/test/unit/plugins/guests/redhat/cap/change_host_name_test.rb +++ b/test/unit/plugins/guests/redhat/cap/change_host_name_test.rb @@ -7,9 +7,12 @@ describe "VagrantPlugins::GuestRedHat::Cap::ChangeHostName" do end let(:machine) { double("machine") } let(:communicator) { VagrantTests::DummyCommunicator::Communicator.new(machine) } + let(:guest) { double("guest") } before do + allow(guest).to receive(:capability).and_return(nil) allow(machine).to receive(:communicate).and_return(communicator) + allow(machine).to receive(:guest).and_return(guest) communicator.stub_command('hostname -f', stdout: old_hostname) communicator.expect_command('hostname -f') end @@ -17,7 +20,7 @@ describe "VagrantPlugins::GuestRedHat::Cap::ChangeHostName" do after do communicator.verify_expectations! end - + context 'when oldhostname is qualified' do let(:old_hostname) { 'oldhostname.olddomain.tld' } let(:similar_hostname) {'oldhostname'} @@ -26,7 +29,7 @@ describe "VagrantPlugins::GuestRedHat::Cap::ChangeHostName" do include_examples 'inserting hostname in /etc/hosts' include_examples 'swapping simple hostname in /etc/hosts' - include_examples 'swapping qualified hostname in /etc/hosts' + include_examples 'swapping qualified hostname in /etc/hosts' end context 'when oldhostname is simple' do