Sha256: 928c21bc9cbaa0704e6b4593e8f599d721cc204b22b856936d8021f075441e90

Contents?: true

Size: 1.23 KB

Versions: 17

Compression:

Stored size: 1.23 KB

Contents

require "tempfile"
require "yaml"

module VagrantPlugins
  module GuestCoreOS
    module Cap
      class ChangeHostName
        extend Vagrant::Util::GuestInspection::Linux

        def self.change_host_name(machine, name)
          comm = machine.communicate

          if systemd_unit_file?(comm, "system-cloudinit*")
            file = Tempfile.new("vagrant-coreos-hostname")
            file.puts("#cloud-config\n")
            file.puts({"hostname" => name}.to_yaml)
            file.close

            dst = "/var/tmp/hostname.yml"
            svc_path = dst.tr("/", "-")[1..-1]
            comm.upload(file.path, dst)
            comm.sudo("systemctl start system-cloudinit@#{svc_path}.service")
          else
            if !comm.test("hostname -f | grep '^#{name}$'", sudo: false)
              basename = name.split(".", 2)[0]
              comm.sudo("hostname '#{basename}'")

              # Note that when working with CoreOS, we explicitly do not add the
              # entry to /etc/hosts because this file does not exist on CoreOS.
              # We could create it, but the recommended approach on CoreOS is to
              # use Fleet to manage /etc/hosts files.
            end
          end
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 3 rubygems

Version Path
vagrant-unbundled-2.3.6.0 plugins/guests/coreos/cap/change_host_name.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/plugins/guests/coreos/cap/change_host_name.rb
vagrant-unbundled-2.3.3.0 plugins/guests/coreos/cap/change_host_name.rb
vagrant-unbundled-2.3.2.0 plugins/guests/coreos/cap/change_host_name.rb
vagrant-unbundled-2.2.19.0 plugins/guests/coreos/cap/change_host_name.rb
vagrant-unbundled-2.2.18.0 plugins/guests/coreos/cap/change_host_name.rb
vagrant-unbundled-2.2.16.0 plugins/guests/coreos/cap/change_host_name.rb
vagrant-unbundled-2.2.14.0 plugins/guests/coreos/cap/change_host_name.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/plugins/guests/coreos/cap/change_host_name.rb
vagrant-unbundled-2.2.10.0 plugins/guests/coreos/cap/change_host_name.rb
vagrant-unbundled-2.2.9.0 plugins/guests/coreos/cap/change_host_name.rb
vagrant-unbundled-2.2.8.0 plugins/guests/coreos/cap/change_host_name.rb
vagrant-unbundled-2.2.7.0 plugins/guests/coreos/cap/change_host_name.rb
vagrant-unbundled-2.2.6.2 plugins/guests/coreos/cap/change_host_name.rb
vagrant-unbundled-2.2.6.1 plugins/guests/coreos/cap/change_host_name.rb
vagrant-unbundled-2.2.6.0 plugins/guests/coreos/cap/change_host_name.rb
vagrant-unbundled-2.2.5.0 plugins/guests/coreos/cap/change_host_name.rb