Skip to content

Commit

Permalink
Set hostname via Puppet instead of Vagrant
Browse files Browse the repository at this point in the history
Vagrant >=2.2.4 errors out while trying to set the hostname of an LXC
container (<fgrehm/vagrant-lxc#481>). This
combination will soon be common in Cloud VPS instances running Debian
Buster, so work around the bug by pushing hostname setting into our
Puppet code and avoid the Vagrant built-in management for it.

Bug: T236455
Change-Id: Ib1a8fe41a8c858a8a12ecf939fb6c7e55f07704d
  • Loading branch information
bd808 committed Oct 27, 2019
1 parent a610415 commit 3b56f8c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ end

Vagrant.configure('2') do |config|
config.vm.post_up_message = 'Documentation: https://www.mediawiki.org/wiki/MediaWiki-Vagrant'
config.vm.hostname = mwv.boxname + '.mediawiki-vagrant.dev'
config.package.name = 'mediawiki.box'

config.ssh.forward_agent = settings[:forward_agent]
Expand Down Expand Up @@ -273,7 +272,8 @@ Vagrant.configure('2') do |config|
puppet.options << '--color=false' if Vagrant::Util::Platform.windows?

puppet.facter = {
'fqdn' => config.vm.hostname,
'hostname' => mwv.boxname,
'fqdn' => mwv.boxname + '.mediawiki-vagrant.dev',
'git_user' => settings[:git_user],
'forwarded_port' => settings[:http_port],
'forwarded_https_port' => settings[:https_port],
Expand Down
2 changes: 1 addition & 1 deletion lib/mediawiki-vagrant/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def hiera_set(key, value)
#
def boxname
@path.basename.to_s.downcase
.gsub(/[^a-z0-9-]+/, '-')[0..62].gsub(/^-|-/, '')
.gsub(/[^a-z0-9-]+/, '-')[0..62].gsub(/^-|-$/, '')
end

private
Expand Down
27 changes: 27 additions & 0 deletions puppet/modules/mwv/manifests/hostname.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# == Class: mwv::hostname
#
# Set the hostname of the managed vm.
#
# === Parameters
#
# [*hostname*]
# Bare hostname
# [*fqdn*]
# Fully qualified hostname
#
class mwv::hostname (
$hostname,
$fqdn,
) {
exec { 'set-hostname':
command => "/usr/bin/hostnamectl set-hostname ${hostname}",
unless => "/bin/hostname -s|/bin/grep -Eq '^${hostname}'",
}
host { $fqdn:
ensure => 'present',
ip => '127.0.0.2',
host_aliases => [
$hostname,
],
}
}
7 changes: 7 additions & 0 deletions puppet/modules/mwv/manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,11 @@
content => $timezone,
require => Package['tzdata'],
}

# T236455: set hostname
class { '::mwv::hostname':
stage => 'first',
hostname => $::hostname,
fqdn => $::fqdn,
}
}

0 comments on commit 3b56f8c

Please sign in to comment.