Puppet Class: quirks::private::defines

Defined in:
manifests/private/defines.pp

Overview

Defines used by the top-level manifest



2
3
4
5
6
7
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'manifests/private/defines.pp', line 2

class quirks::private::defines {
  # In order to mend the Puppet configuration itself as we progress,
  # all tasks are applied in a "puppet apply" subprocess.
  #
  # === Parameters:
  #
  # $puppet_mantra::  The snippet to pass to a sub-"puppet apply -e";
  #                   defaults to $title.
  #                   *Attention*: it MUST NOT use single quotes.
  define run_puppet_apply_to_fixpoint(
      $puppet_mantra = undef
    ) {
    if ($puppet_mantra == undef) {
      $exec_descr = "run puppet apply -e ${title} to fixpoint"
      $_actual_puppet_mantra = $title
    } else {
      $exec_descr = $title
      $_actual_puppet_mantra = $puppet_mantra
    }
    $log_file = inline_template('<%= require("tempfile")
       Tempfile.new("epflsti-quirks-").path %>')
    exec { $exec_descr:
      command => "cat ${log_file} >&2; false",
      path => $::path,
      unless => inline_template('true ; set -x ;  exec > <%= @log_file %> 2>&1
      for try in $(seq 1 5); do
         puppet apply -e "<%= @_actual_puppet_mantra %>"
         errorcode=$?
         case "$errorcode" in
           2) continue ;;
           0) rm -f <%= @log_file %>; exit 0 ;;
           *)
             (set +x; tput bold; tput setaf 4; echo >&2 "======================================= sub-Puppet logs (more legible) were kept in <%= @log_file %> ======================================="; tput sgr0)
             exit "$errorcode" ;;
         esac
      done
      ')
    }
  }
  define subquirk() {
    ::quirks::private::defines::run_puppet_apply_to_fixpoint {
      "class { 'quirks::private::subquirks::${title}': }":
    }
  }

  define subquirk_incompatible_module($req_3x, $req_4x,
                                     $req_5x = undef, $req_6x = undef,
                                     $req_7x = undef, $req_8x = undef,
                                     $req_9x = undef) {
    $puppet_mantra = inline_template(
      "include quirks::private::puppet_module_versions

      ::quirks::private::puppet_module_versions::incompatible_module {
        '<%= @title %>':
          req_3x => '<%= @req_3x %>',
          req_4x => '<%= @req_4x %>'
          <% if defined?(@req_5x) %>
          , req_5x => '<%= @req_5x %>'
          <% end %>
      }"
    )
    ::quirks::private::defines::run_puppet_apply_to_fixpoint {
      "incompatible_module ${title}":
        puppet_mantra => $puppet_mantra
    }
  }
}