Defined Type: autofs::mapping

Defined in:
manifests/mapping.pp

Summary

Defined type to manage a single filesystem mapping in a single map file.

Overview

When ensured ‘present’, a autofs::mapfile resource managing the overall target map file must also be present in the catalog. This resource implements Autofs’s ‘sun’ map format, which is the default.

It is not supported to declare multiple autofs::mappings with the same key, targetting the same map file, and ensured ‘present’.

Examples:

Options given as a string

autofs::mapping{ '/etc/auto.data_data':
  mapfile => '/etc/auto.data',
  key     => 'data',
  options => 'rw,sync,suid',
  fs      => 'storage_host.my.com:/path/to/data'
}

Options given as an array

autofs::mapping{ '/etc/auto.data_data':
  mapfile => '/etc/auto.data',
  key     => 'data',
  options => ['ro', 'noexec', 'nodev'],
  fs      => 'storage_host.my.com:/path/to/data'
}

No options

autofs::mapping{ '/etc/auto.data_data':
  mapfile => '/etc/auto.data',
  key     => 'data',
  fs      => 'storage_host.my.com:/path/to/data'
}

Parameters:

  • ensure (Enum['present', 'absent']) (defaults to: 'present')

    Whether the mapping should be present in the target mapfile; ensuring ‘absent’ is not meaningfully different from omitting the resource declaration altogether

  • fs (Variant[String[1], Array[String[1]]])

    the remote filesystem to mount

  • key (String[1])

    the autofs key for this mapping. For indirect maps it is the basename of the mountpoint directory for $fs (not to be confused with an autofs mount point, which is the parent directory). For direct maps it is the absolute path to the mountpoint directory.

  • mapfile (Stdlib::Absolutepath)

    the absolute path to the file containing the Autofs map to which this mapping belongs

  • options (Optional[Autofs::Options]) (defaults to: undef)

    a comma-delimited mount options string or an array of individual mount options; neither individual options nor the overall option list should be specified with a leading hyphen (-); that is part of the map file format, not of the options themselves, and it is provided by this resource

  • order (Integer) (defaults to: 10)

    an integer describing the relative order of the mapping represented by this resource within the target map file (default 10). The order matters only if the same kay is enrolled more than once in the map, in which case only the first is effective.

See Also:

Author:

  • Vox Pupuli <voxpupuli@groups.io>

  • David Hollinger III <david.hollinger@moduletux.com>



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'manifests/mapping.pp', line 62

define autofs::mapping (
  Stdlib::Absolutepath $mapfile,
  String[1] $key,
  Variant[String[1], Array[String[1]]] $fs,
  Enum['present', 'absent'] $ensure  = 'present',
  Optional[Autofs::Options] $options = undef,
  Integer $order                     = 10,
) {
  unless $ensure == 'absent' {
    $formatted_key = if $key =~ /[[:blank:]"]/ {
      String($key, '%#p')
    } else {
      $key
    }
    # Format the options string, relying to some extent on the
    # $options parameter, if specified, to indeed match the
    # Autofs::Options data type
    if ($options =~ Undef) or ($options =~  Array[Any,0,0]) { # an empty array
      $formatted_options = ''
    } else {
      $prelim_options = $options ? {
        Array   => join($options, ','),  # a non-empty array
        String  => $options,
        default => fail('Unexpected value for parameter $options')
      }
      $formatted_options = $prelim_options ? {
        # even though the user *shouldn't* provide the hyphen, we accommodate
        # them doing so.  But only at the head of the option list, not
        # internally.
        /\A-/   => $prelim_options,
        default => "-${prelim_options}",
      }
    }
    $formatted_fs = [$fs].flatten.map |$value| { if $value =~ /[[:blank:]"]/ { String($value, '%#p') } else { $value } }.join(' ')

    # Declare an appropriate fragment of the target map file
    if $formatted_key == '+' {
      $content = "${formatted_key}${formatted_fs}\n"
    } else {
      $content = "${formatted_key}\t${formatted_options}\t${formatted_fs}\n"
    }

    concat::fragment { "autofs::mapping/${title}":
      target  => $mapfile,
      content => $content,
      order   => $order,
    }
  }
}