Browse Source

[common] Add the common module

Gabriel Corona 8 years ago
parent
commit
ba2d60be22

+ 5 - 3
README.md

@@ -6,11 +6,13 @@
 
 * `Puppetfile` list of external modules to load in `modules/`;
 
-* `modules/` contains the modules decmlared by `Puppetfile` and managed
-  by `r10k`;
+* `modules/` contains the modules declared by `Puppetfile` and managed
+  by `r10k`,
 
   * `modules/ldn` contains the private stuff (ideally it should be hiera files
-    only),
+    only);
+
+* `modules-ldn/` contains some modules local to this repository.
 
 ## Installation
 

+ 1 - 1
environment.conf

@@ -1,5 +1,5 @@
 # Managed by puppet
 environment_timeout=0
 manifest=manifests/00_site.pp
-modulepath=modules
+modulepath=modules:modules-ldn
 #config_version=/usr/local/bin/get_env_version.sh $environment

+ 1 - 0
manifests/00_site.pp

@@ -1,4 +1,5 @@
 node 'base' {
+  include '::common'
   include '::ldn::users'
 }
 

+ 14 - 0
modules-ldn/common/README.md

@@ -0,0 +1,14 @@
+# common
+
+## Description
+
+common puppet module for LDN (http://ldn-fai.net/)
+
+## Authors
+
+Lorraine Data Network (c) 2013
+
+* Author: Sebastien Badia (<seb@sebian.fr>)
+* Date: 2013-12-07 15:28:58 +0100
+* Maintainer: Sebastien Badia (<seb@sebian.fr>)
+

+ 50 - 0
modules-ldn/common/files/cronic

@@ -0,0 +1,50 @@
+#!/bin/bash
+# MANAGED BY PUPPET
+# Module:: sharedadm
+
+# Cronic v2 - cron job report wrapper
+# Copyright 2007 Chuck Houpt. No rights reserved, whatsoever.
+# Public Domain CC0: http://creativecommons.org/publicdomain/zero/1.0/
+
+set -eu
+
+OUT=/tmp/cronic.out.$$
+ERR=/tmp/cronic.err.$$
+TRACE=/tmp/cronic.trace.$$
+
+set +e
+"$@" >$OUT 2>$TRACE
+RESULT=$?
+set -e
+
+PATTERN="^${PS4:0:1}\\+${PS4:1}"
+if grep -aq "$PATTERN" $TRACE
+then
+    ! grep -av "$PATTERN" $TRACE > $ERR
+else
+    ERR=$TRACE
+fi
+
+if [ $RESULT -ne 0 -o -s "$ERR" ]
+    then
+    echo "Cronic detected failure or error output for the command:"
+    echo "$@"
+    echo
+    echo "RESULT CODE: $RESULT"
+    echo
+    echo "ERROR OUTPUT:"
+    cat "$ERR"
+    echo
+    echo "STANDARD OUTPUT:"
+    cat "$OUT"
+    if [ $TRACE != $ERR ]
+    then
+        echo
+        echo "TRACE-ERROR OUTPUT:"
+        cat "$TRACE"
+    fi
+fi
+
+rm -f "$OUT"
+rm -f "$ERR"
+rm -f "$TRACE"

+ 109 - 0
modules-ldn/common/manifests/init.pp

@@ -0,0 +1,109 @@
+# Module:: common
+# Manifest:: init.pp
+#
+# Lorraine Data Network http://ldn-fai.net/
+# Author:: Sebastien Badia (<seb@sebian.fr>)
+# Date:: 2013-12-07 15:28:58 +0100
+# Maintainer:: Sebastien Badia (<seb@sebian.fr>)
+#
+
+# Class:: common
+#
+#
+class common {
+
+  class {'dnsclient':
+    nameservers => hiera_array('nameservers', undef),
+    options     => 'UNSET',
+    search      => hiera("domain"),
+    domain      => hiera("domain"),
+  }
+
+  # TODO, apt-proxy
+
+  # Remove apt-xapian-index (on low memory vm, xapian take a lot of RAM/CPU)
+  # https://bugs.launchpad.net/ubuntu/+source/apt-xapian-index/+bug/363695
+  package {'apt-xapian-index':
+    ensure => purged,
+  }
+
+  # Setup timezone
+  class {
+    'timezone':
+      timezone    => hiera("timezone"),
+      autoupgrade => false;
+  }
+
+  class {'locales':
+    default_locale => 'en_US.UTF-8 UTF-8',
+    locales        => hiera("locales")
+  }
+
+  package {
+    ['tmux','screen','netcat','htop','rsync','host','dmraid',
+      'man-db','vim','zsh','bash','iputils-ping','dnsutils',
+      'python-apt','aptitude','debian-goodies','molly-guard']:
+      ensure => installed;
+  }
+
+  ensure_packages(['logrotate'])
+
+  # TODO, sudo / sudo-ldap
+  # TODO, sudo %puppetdev
+  # TODO, ssh_auth_sock
+
+  file {
+    '/usr/local/bin/cronic':
+      ensure => file,
+      source => 'puppet:///modules/common/cronic',
+      owner  => root,
+      group  => root,
+      mode   => '0755';
+  }
+
+  file {
+    '/etc/alternatives/editor':
+      ensure  => link,
+      target  => '/usr/bin/vim',
+      require => Package['vim'];
+    '/bin/sh':
+      ensure => link,
+      target => '/bin/dash';
+  }
+
+  file {
+    '/etc/hostname':
+      ensure  => file,
+      content => $::fqdn,
+      owner   => root,
+      group   => root,
+      mode    => '0644',
+      notify  => Exec['reload hostname'];
+    '/etc/mailname':
+      ensure  => file,
+      content => $::fqdn,
+      owner   => root,
+      group   => root,
+      mode    => '0644';
+  }
+
+  exec {
+    'reload hostname':
+      command     => '/bin/sh /etc/init.d/hostname.sh start',
+      user        => root,
+      refreshonly => true,
+      logoutput   => on_failure;
+  }
+
+  # TODO, setup sources
+  # TODO, setup ssh
+
+  class {'::motd': template => 'common/motd.erb'; }
+
+  # Avoid a strange bug with facter
+  # Could not retrieve fact='selinux', resolution='<anonymous>'': Invalid argument - /proc/self/attr/current
+  if $::selinux == 'false' {
+    file {'/selinux/enforce': ensure => absent }
+  }
+
+} # Class:: common

+ 15 - 0
modules-ldn/common/templates/motd.erb

@@ -0,0 +1,15 @@
+
+  server: <%= @fqdn %>
+  system: <%= @operatingsystem %> <%= @operatingsystemrelease %>, kernel <%= @kernelrelease %>, puppet <%= @puppetversion %>
+     cpu: <%= @physicalprocessorcount  %>/<%= @processorcount %> (<%= @processor0 %>)
+  memory: <%if has_variable?("memorytotal") %><%= @memorytotal %><% else %><%= @memorysize %><% end %>
+<% @interfaces.split(',').each do |i| -%>
+<%- if i != "lo" and not i.start_with?('phy_br','int_br','qbr','tap','qvo','qvb','veth','tmp','he','sit','br267') %>
+    <%= i -%>: <%= scope.lookupvar("macaddress_#{i}") -%><% if has_variable?("ipaddress_#{i}") -%> / <%= scope.lookupvar("ipaddress_#{i}") -%><% end -%><% if has_variable?("ipaddress6_#{i}") %> / <%= scope.lookupvar("ipaddress6_#{i}") -%><% end -%><% end -%>
+<% end %>
+
+ modules: <% classes.each do |klass| -%>
+<% if klass != "settings" and klass[-6,6] != "params" and klass != @fqdn and klass != "concat::setup" -%>
+<%= klass %> <% end -%>
+<% end %>
+