Defined Type: environment_variable::path_element

Defined in:
manifests/path_element.pp

Overview

Environment_variable::Path_element

Add an element to the path. Can be called multiple times to allow the path to be built progressively

Parameters:

  • path (Any) (defaults to: $title)

    The path element to add to $PATH

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

    Whether to add or remove this element



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'manifests/path_element.pp', line 8

define environment_variable::path_element(
  $path                             = $title,
  Enum['present','absent'] $ensure  = present,
) {
  case $facts['kernel'] {
    "windows": {
      # progressively build up the path with seperate resources.
      # insert path element on windows without any ordering (to allow multiple inserts)
      windows_env { "path_element_${path}":
        ensure   => $ensure,
        variable => 'PATH',
        value    => $path,
      }
    }

    "Linux": {
      # drop each line into a file so elements can be managed individually
      $safe_name = regsubst($path, /\//, "_", "G")
      $file_ensure = $ensure ? {
        "present" => "file",
        default   => "absent",
      }

      # leading slash needs to be converted for safety which means we still get
      # 2x underscores between typename and safe name
      file { "/etc/profile.d/environment_variable__path_element_${safe_name}.sh":
        ensure  => $file_ensure,
        owner   => "root",
        group   => "root",
        mode    => "0644",
        content => "PATH=${path}:\$PATH",
      }
    }

    default: {
      fail("#{module_name} does not support ${facts['os']['family']}")
    }
  }
}