add ff_gw::sysadmin::hostname class

This commit is contained in:
Martin Schuette 2014-05-18 20:59:41 +02:00
parent af4297c8f7
commit 0a774265d9
2 changed files with 62 additions and 4 deletions

View file

@ -54,6 +54,10 @@ class { 'ff_gw::sysadmin':
zabbixserver => 'argos.mschuette.name',
muninserver => '78.47.49.236',
# optional, configure hostname and public IP
sethostname => 'gw12.hamburg.freifunk.net',
setip => '5.45.105.34',
# also optional, let puppet control user accounts:
accounts => {
mschuett => {

View file

@ -1,10 +1,18 @@
# kitchen sink class for various small settings
class ff_gw::sysadmin($zabbixserver = '127.0.0.1', $muninserver = '127.0.0.1', $accounts = {}) {
class ff_gw::sysadmin($zabbixserver = '127.0.0.1', $muninserver = '127.0.0.1', $sethostname = false, $setip = false, $accounts = {}) {
if $sethostname and $setip {
# set system hostname
class { 'ff_gw::sysadmin::hostname':
newname => $sethostname,
newip => $setip,
}
}
# use backports repo
apt::source { 'wheezy-backports':
location => 'http://ftp.de.debian.org/debian/',
release => 'wheezy-backports',
repos => 'main',
location => 'http://ftp.de.debian.org/debian/',
release => 'wheezy-backports',
repos => 'main',
}
# some more packages
package {
@ -126,3 +134,49 @@ env.estimate 1';
enable => true;
}
}
class ff_gw::sysadmin::hostname($newname, $newip) {
# short name
$alias = regsubst($newname, '^([^.]*).*$', '\1')
# clean old names
if "$::hostname" != "$alias" {
host { "$hostname": ensure => absent }
}
if "$::fqdn" != "$newname" {
host { "$fqdn": ensure => absent }
}
# rewrite config files:
host { "$newname":
ensure => present,
ip => $newip,
alias => $alias ? {
"$hostname" => undef,
default => $alias
},
before => Exec['hostname.sh'],
}
file { '/etc/mailname':
ensure => present,
owner => 'root',
group => 'root',
mode => 644,
content => "${newname}\n",
}
file { '/etc/hostname':
ensure => present,
owner => 'root',
group => 'root',
mode => 644,
content => "${newname}\n",
notify => Exec['hostname.sh'],
}
exec { 'hostname.sh':
command => '/etc/init.d/hostname.sh start',
refreshonly => true,
}
}