From: karim hamidou Date: Sat, 9 Nov 2013 19:42:39 +0000 (+0100) Subject: WIP - refactoring puppet files X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=7a9f5db6cf16bdb074e2ea85b7a3f626668c198f;p=kite.git WIP - refactoring puppet files --- diff --git a/manifests/default.pp b/manifests/default.pp index d81498c..fc9f7e8 100644 --- a/manifests/default.pp +++ b/manifests/default.pp @@ -1,35 +1,57 @@ +# this is the main config file for puppet + +$server_name = "kitebox.dev" + exec {"apt-get update": path => ["/usr/bin/", "/usr/sbin"], } -$packages = ["postfix", "python", "bpython"] +$packages = ["python", "bpython"] + +$kite_gid = "5000" +$kite_uid = "500" group { "kite": - ensure => "present" + ensure => "present", + gid => $kite_gid } package { $packages: ensure => present, - require => Exec["apt-get update"] -} - -service {'postfix': - ensure => running, - enable => true, - hasstatus => true, - hasrestart => true, - require => Package["postfix"] + require => Exec["apt-get update"], } user { "kite": require => Group["kite"], ensure => present, gid => "kite", + uid => $kite_uid, shell => "/bin/true", home => "/home/kite", managehome => true, } +# comes from http://serverfault.com/a/524188 +class hostname ($fqdn) { + file { "/etc/hostname": + ensure => present, + owner => root, + group => root, + mode => 644, + content => "$fqdn\n", + notify => Exec["set-hostname"], + } + + exec { "set-hostname": + command => "/bin/hostname -F /etc/hostname", + unless => "/usr/bin/test `hostname` = `/bin/cat /etc/hostname`", + } +} + +class {'hostname': + fqdn => $server_name +} + file { "/var/kitemail": require => User["kite"], ensure => "directory", @@ -37,41 +59,18 @@ file { "/var/kitemail": group => "kite", } - # nginx class {'nginx': - server_name => "example.com", + server_name => $server_name, appdir => "/home/kite/app", require => Exec["apt-get update"] } -#nginx::resource::location {'kiteapp': -# ensure => present, -# www_root => '/home/kite/app', -# location => '/', -# vhost => 'kiteapp' -#} - -# code comes from : https://bitbucket.org/daks/puppet-postfix/src/2e93e657cab6/manifests/definitions/config.pp -define postfix_config ($ensure = present, $value, $nonstandard = false) { - exec {"postconf -e ${name}='${value}'": - path => ["/usr/bin/", "/usr/sbin"], - unless => $nonstandard ? { - false => "test \"x$(postconf -h ${name})\" == 'x${value}'", - true => "test \"x$(egrep '^${name} ' /etc/postfix/main.cf | cut -d= -f2 | cut -d' ' -f2)\" == 'x${value}'", - }, - notify => Service["postfix"], - require => Package["postfix"] - } -} - -postfix_config { 'home_mailbox': - value => "Maildir/", -} - -# deliver a copy of all the received emails to user kite -postfix_config { 'always_bcc': - value => "kite", +# postfix +class {'postfix': + server_name => $server_name, + appdir => "/home/kite/app", + require => Exec["apt-get update"] } # deploy files diff --git a/puppet_modules/postfix/manifests/.init.pp.swo b/puppet_modules/postfix/manifests/.init.pp.swo new file mode 100644 index 0000000..5bae714 Binary files /dev/null and b/puppet_modules/postfix/manifests/.init.pp.swo differ diff --git a/puppet_modules/postfix/manifests/init.pp b/puppet_modules/postfix/manifests/init.pp new file mode 100644 index 0000000..5ac38ec --- /dev/null +++ b/puppet_modules/postfix/manifests/init.pp @@ -0,0 +1,82 @@ +# a class for installing and configuring a basic nginx setup + +class postfix ($server_name, $appdir) { + $packages = ["postfix"] + + package { $packages: + ensure => present, + } + + service {'postfix': + ensure => running, + enable => true, + hasstatus => true, + hasrestart => true, + require => Package["postfix"], + } + + # code comes from : https://bitbucket.org/daks/puppet-postfix/src/2e93e657cab6/manifests/definitions/config.pp + define postfix_config ($ensure = present, $value, $nonstandard = false) { + exec {"postconf -e ${name}='${value}'": + path => ["/usr/bin/", "/usr/sbin"], + unless => $nonstandard ? { + false => "test \"x$(postconf -h ${name})\" == 'x${value}'", + true => "test \"x$(egrep '^${name} ' /etc/postfix/main.cf | cut -d= -f2 | cut -d' ' -f2)\" == 'x${value}'", + }, + notify => Service["postfix"], + require => Package["postfix"] + } + } + + postfix_config { 'home_mailbox': + value => "Maildir/", + } + + postfix_config { 'virtual_mailbox_domains': + value => "/etc/postfix/vhosts", + } + + postfix_config { 'virtual_mailbox_base': + value => "/home/kite", + } + + postfix_config { 'virtual_mailbox_maps' : + value => "hash:/etc/postfix/vmaps" + } + + postfix_config { 'virtual_minimum_uid': + value => "500", + } + + postfix_config { 'virtual_uid_maps': + value => "static:5000", + } + + postfix_config { 'virtual_gid_maps': + value => "static:5000", + } + + file {"/etc/postfix/vhosts": + owner => "root", + group => "root", + content => template('postfix/postfix_vhosts.erb'), + } + + file {"/etc/postfix/vmaps": + owner => "root", + group => "root", + content => template('postfix/postfix_vmaps.erb'), + } + + exec {"postmap /etc/postfix/vmaps": + path => ["/usr/bin/", "/usr/sbin"], + require => File["/etc/postfix/vmaps"], + notify => Service["postfix"], + } + + # deliver a copy of all the received emails to user kite + #postfix_config { 'always_bcc': + # value => "kite", + #} + +} diff --git a/puppet_modules/postfix/templates/postfix_vhosts.erb b/puppet_modules/postfix/templates/postfix_vhosts.erb new file mode 100644 index 0000000..d4e436b --- /dev/null +++ b/puppet_modules/postfix/templates/postfix_vhosts.erb @@ -0,0 +1 @@ +<%= server_name %> diff --git a/puppet_modules/postfix/templates/postfix_vmaps.erb b/puppet_modules/postfix/templates/postfix_vmaps.erb new file mode 100644 index 0000000..18c1e93 --- /dev/null +++ b/puppet_modules/postfix/templates/postfix_vmaps.erb @@ -0,0 +1 @@ +kite@<%= server_name %> <%= server_name %>/kite