Puppet Class: lmhosts

Defined in:
manifests/init.pp

Summary

Manage the /etc/samba/lmhosts file.

Overview

This class manages entries within the Samba lmhosts file, based on documentation found at bit.ly/2L2zaYJ

Examples:

class { 'lmhosts' :
  list => [
    {
      'address' => '127.0.0.1',
      'host'    => 'localhost',
    },
    { 'address' => '192.168.1.100',
      'host'    => 'pdc',
    }
  ],

Parameters:

  • list (Lmhosts::List) (defaults to: [ { 'address' => '127.0.0.1', 'host' => 'localhost' } ])

    Ordered List of lmhosts entries.

  • no_export (Boolean) (defaults to: false)

    If true, do not export the current host for use by other nodes.

  • no_import (Boolean) (defaults to: false)

    If true, do not add exported host entries to this node’s lmhosts file.

  • path (Stdlib::Absolutepath) (defaults to: [ '/etc/samba/lmhosts', "${facts['windows_env']['SYSTEMROOT']}\\System32\\drivers\\etc\\lmhosts" ][$facts['kernel'] ? { 'windows' => 1, default => 0 }])

    Absolute path to the lmhosts file to manage.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'manifests/init.pp', line 30

class lmhosts(
  Lmhosts::List        $list      = [
    {
      'address' => '127.0.0.1',
      'host'    => 'localhost'
    }
  ],
  Boolean              $no_export = false,
  Boolean              $no_import = false,
  Stdlib::Absolutepath $path      = [
    '/etc/samba/lmhosts',
    "${facts['windows_env']['SYSTEMROOT']}\\System32\\drivers\\etc\\lmhosts"
  ][$facts['kernel'] ? { 'windows' => 1, default => 0 }]
){
  # Create the lmhosts file.
  concat { $path:
    ensure => 'present',
  }

  # Add static hosts not in the catalog.
  $list.each |Integer[0,9999] $index, Lmhosts::Entry $entry| {
    $type = $entry ? {
      Lmhosts::Alternates::Resource => 'lmhosts::alternates',
      Lmhosts::Host::Resource       => 'lmhosts::host',
      Lmhosts::Include::Resource    => 'lmhosts::include',
    }
    $order = String($index, '%04d')
    create_resources($type, { "${path} ${order}" => $entry })
  }

  # Export the current host.
  unless $no_export {
    $hostname = $facts['networking']['hostname']
    @@lmhosts::host { "${path} ${hostname} (exported)":
      address => $facts['networking']['ip'],
      host    => $hostname,
      index   => 'catalog',
      path    => $path,
      preload => true,
    }
  }

  # Collect all exported hosts.
  unless $no_import {
    Lmhosts::Host <<| |>>
  }
}