Zachu / Jani Korhonen

Linuxin keskitetty hallinta – Viikko 48

Modulini aiheena on töissäni käytettävän PISA-järjestelmän tietokoneiden hallintaan keskittynyt moduli. Modulin tehtävänä on asentaa kyseisten tietokoneiden tarvitsemat ohjelmat (Openbox ja Chromium-selain), asettaa nämä käynnistymään automaattisesti ja hallita näiden konfiguraatiotiedostoja.

Modulin rakenne

$ tree

.
└── pisa
    ├── manifests
    │   ├── init.pp
    │   ├── pisa_chromium.pp
    │   ├── pisa_mingetty.pp
    │   ├── pisa_openbox.pp
    │   └── pisa_user.pp
    ├── Modulefile
    └── templates
        ├── pisa_chromium_monitor.erb
        ├── pisa_openbox_autostart.erb
        ├── pisa_openbox_bash_profile.erb
        ├── pisa_openbox_menu.erb
        ├── pisa_openbox_rc.erb
        └── pisa_tty1.erb

Template-tiedostoissa on Chromium-selaimen päällä pitävä monitorointi sekä openboxin konfiguraatiotiedostot.

Luokkien sisälmykset

$ cat pisa/manifests/pisa_user.pp

# Class: pisa_user
#
# Puppet class that manages user for PISA system
#
# 2012-12-11    Jani Korhonen 
#
# Paramateters:
#   * Username - Name of the user to be created
#       Possible values: string
#
# Actions: Manages user for PISA system
#
# Requires:
#
# Sample usage:
#   class { 'pisa_user':
#       username => 'xubuntu',
#   }
#
class pisa_user (
    $username
) {
    File {
        owner => $username,
        group => $username,
    }

    user { $username:
        ensure => present,
        managehome => true,
        home => "/home/${username}",
    }
    file {"/home/${username}":
        ensure => directory,
        owner => $username,
        group => $username,
    }
}

$ cat pisa/manifests/pisa_openbox.pp

# Class: pisa_openbox
#
# Puppet class that manages Openbox Window Manager and its settings as they're needed in PISA system
#
# 2012-12-11    Jani Korhonen 
#
# Paramateters:
#   * Username - Name of the user which will get the openbox configurations
#       Possible values: string
#
#   * Autostart - Start Openbox and X automatically when logged in
#       Possible values: [true,false]
#       Default: true
#
#   * Autostart_chromium - Start Chromium automatically (when Openbox starts) and monitor it if it's closed
#       Possible values: [true,false,monitor]
#       Default: true
#
#   * Ensure - Ensure parameter for openbox and xorg
#       Possible values: [present, installed, absent, purged, held, latest]
#       Default: present
#
# Actions: Manages Openbox Window Manager and its settings
#
# Requires:
#
# Sample usage:
#   class { 'pisa_openbox':
#       ensure => present
#       autostart => true,
#       username => 'xubuntu',
#   }
#
class pisa_openbox (
    #Parameters
    $username,
    $autostart = true,
    $autostart_chromium = true,
    $ensure = present,
) {
    File {
        owner => $username,
        group => $username,
    }

    package {'xorg':
        ensure => $ensure,
    }
    package {'openbox':
        ensure => $ensure,
    }

    file {["/home/${username}/.config","/home/${username}/.config/openbox"]:
        ensure => directory,
        before => [
            File["/home/${username}/.config/openbox/rc.xml"],
            File["/home/${username}/.config/openbox/menu.xml"]
        ],
        require => [
            Package['openbox'],
            User[$username]
        ],
    }

    file {"/home/${username}/.config/openbox/rc.xml":
        ensure => file,
        content => template('pisa/pisa_openbox_rc.erb')
    }
    file {"/home/${username}/.config/openbox/menu.xml":
        ensure => file,
        content => template('pisa/pisa_openbox_menu.erb'),
    }
    file {"/home/${username}/.config/openbox/autostart":
        ensure => file,
        content => template('pisa/pisa_openbox_autostart.erb'),
    }

    if $autostart {
        file {"/home/${username}/.bash_profile/":
            ensure => file,
            content => template('pisa/pisa_openbox_bash_profile.erb'),
        }
    }
    else {
        file {"/home/${username}/.bash_profile/":
            ensure => absent,
        }
    }
}

$ cat pisa/manifests/pisa_chromium.pp

# Class: pisa_chromium
#
# Puppet class that manages Chromium Browser and its settings as they're needed in PISA system
#
# 2012-12-11    Jani Korhonen 
#
# Paramateters:
#   * Url - URL that Chromium opens once it's launched
#       Possible values: string
#       Default: http://www.google.com
#
#   * LauncherPath - Path where to put the launcher file pisa_chromium
#       Possible values: string
#       Default: /usr/bin
#
#   * Ensure - Ensure parameter for Chromium-browser
#       Possible values: [present, installed, absent, purged, held, latest]
#       Default: present
#
# Actions: Manages Chromium Browser and its settings for PISA system
#
# Requires: pisa_openbox
#
# Sample usage:
#   class { 'pisa_chromium':
#       url => 'http://www.google.com',
#       launcherpath => '/usr/bin',
#       ensure => present,
#   }
#
class pisa_chromium (
    #Parameters
    $url = 'http://www.google.com',
    $launcherpath = '/usr/bin',
    $ensure = present,
) {
    package { 'chromium-browser':
        ensure => $ensure,
    }

    #PISA_Chromium launcher
    file {"${launcherpath}/pisa_chromium":
        ensure => present,
        path => "${launcherpath}/${name}",
        content => "chromium-browser --incognito --kiosk ${url}",
        mode => 755,
        owner => 'root',
        group => 'root',
    }

    #PISA_Chromium monitor
    file {"${launcherpath}/pisa_chromium_monitor":
        ensure => present,
        content => template('pisa/pisa_chromium_monitor.erb'),
        mode => 755,
        owner => 'root',
        group => 'root',
    }
}

$ cat pisa/manifests/pisa_mingetty.pp

# Class: pisa_mingetty
#
# Puppet class that makes a certain user log in automatically
#
# 2012-12-11    Jani Korhonen 
#
# Paramateters:
#   * Username - Name of the user which will get the openbox configurations
#       Possible values: string
#
#   * Ensure - Ensure parameter for mingetty
#       Possible values: [present, installed, absent, purged, held, latest]
#       Default: present
#
# Actions: Manages user for PISA system
#
# Requires:
#
# Sample usage:
#   class { 'pisa_mingetty':
#       username => 'xubuntu',
#   }
#
class pisa_mingetty(
    $ensure = 'present',
    $username,
) {

    package {'mingetty':
        ensure => $ensure,
    }

    file {'/etc/init/tty1.conf':
        ensure => file,
        content => template('pisa/pisa_tty1.erb'),
        owner => 'root',
        group => 'root',
    }
}

$ cat pisa/manifests/init.pp

# Class: pisa
#
# Puppet module that manages the PISA system components
#
# 2012-12-11    Jani Korhonen 
#
# Tested platforms
#   - Xubuntu 12.04
# with command
#   puppet apply --modulepath  -e 'class{"pisa":location=>"test"}'
#
# Paramateters:
#   * Location - Location where the node will physically be. This one decides the URL the system opens by default
#       Possible values: string
#
# Actions: Manages the PISA system components
#
# Requires:
#
# Sample usage:
#   class { 'pisa':
#       location => 'test',
#   }
#
# TODO: Prevent users from closing the browser by disabling CTRL and ALT keys
# TODO: Prevent users closing the X with CTRL + ALT + Backspace combination
# TODO: Prevent users from changing the TTY
# TODO: Manage user home directories
# TODO: Install Softwedge - Barcode scanner virtual com port driver or something like that
# TODO: Disable screensaver
#
class pisa($location) {
    $user='pisa'

    class{'pisa_user':
        username => $user,
    }

    class{'pisa_mingetty':
        username => $user,
        ensure => present,
    }

    class{'pisa_openbox':
        autostart => true,
        autostart_chromium => monitor,
        username => $user,
        ensure => present,
    }
    class{'pisa_chromium':
        url => "http://10.41.41.10/pisa/${location}/screen/",
        ensure => present,
    }
}

Koko paketin voi ladata linkistä pisa.tar.gz

Kirjoita vastaus

Sähköpostia ei julkaista. Vaaditut kentät on merkitty *-merkillä.

Voit käyttää seuraavia HTML-tageja: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

Under heavy construction :(