diff --git a/README.md b/README.md index 1578699..b492000 100644 --- a/README.md +++ b/README.md @@ -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 => { diff --git a/manifests/sysadmin.pp b/manifests/sysadmin.pp index a251f2c..2983041 100644 --- a/manifests/sysadmin.pp +++ b/manifests/sysadmin.pp @@ -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, + } +}