Defined Type: apptainer::plugin

Defined in:
manifests/plugin.pp

Summary

Manage Apptainer plugin

Overview

Examples:

install log plugin


apptainer::plugin { 'github.com/apptainer/apptainer/log-plugin':
  source_dir => 'examples/plugins/log-plugin',
}

Parameters:

  • source_dir (Optional[String]) (defaults to: undef)

    The plugin source directory This path must be relative to Apptainer source directory $apptainer::install::source::source_dir

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

    Whether to install (present) or uninstall (absent) the plugin

  • sif_name (Optional[String]) (defaults to: undef)

    The name of the SIF image to use for install after the plugin is compiled. The default is to use part after last / in the plugin name so plugin examples/plugins/log-plugin will have SIF name of log-plugin.sif.



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
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
# File 'manifests/plugin.pp', line 19

define apptainer::plugin (
  Enum['present', 'absent'] $ensure = 'present',
  Optional[String] $source_dir = undef,
  Optional[String] $sif_name = undef,
) {
  include apptainer

  if $apptainer::install_method != 'source' {
    fail("Define apptainer::plugin ${name} can only be done for source installation")
  }

  if $ensure == 'present' and $source_dir =~ Undef {
    fail("Define apptainer::plugin ${name} must define source_dir")
  }

  $exec_path = "${apptainer::prefix}/bin:${apptainer::source_exec_path}"

  if $ensure == 'present' {
    $basename = split($name, '/')[-1]
    $_sif_name = pick($sif_name, "${basename}.sif")
    $sif_path = "${apptainer::install::source::source_dir}/${source_dir}/${_sif_name}"

    if $apptainer::manage_go and $apptainer::rebuild_on_go {
      Class['golang'] ~> Exec["apptainer-plugin-recompile-${name}"]
    }

    if $facts['apptainer_version'] and $facts['apptainer_version'] != $apptainer::version {
      exec { "apptainer-plugin-uninstall-for-upgrade-${name}":
        path    => $exec_path,
        command => "apptainer plugin uninstall ${name}",
        onlyif  => "apptainer plugin list | grep '${name}'",
        before  => Class['apptainer::install::source'],
      }
    }

    exec { "apptainer-plugin-compile-${name}":
      path        => $exec_path,
      environment => $apptainer::install::source::build_env,
      command     => "apptainer plugin compile ${source_dir}",
      cwd         => $apptainer::install::source::source_dir,
      creates     => $sif_path,
      require     => Class['apptainer::install::source'],
    }

    exec { "apptainer-plugin-recompile-${name}":
      path        => $exec_path,
      environment => $apptainer::install::source::build_env,
      command     => "apptainer plugin compile ${source_dir}",
      cwd         => $apptainer::install::source::source_dir,
      onlyif      => "test -f ${sif_path}",
      refreshonly => true,
      require     => Class['apptainer::install::source'],
      notify      => Exec["apptainer-plugin-reinstall-${name}"],
    }

    exec { "apptainer-plugin-install-${name}":
      path    => $exec_path,
      command => "apptainer plugin install ${sif_path}",
      unless  => "apptainer plugin list | grep '${name}'",
      require => Exec["apptainer-plugin-compile-${name}"],
    }

    exec { "apptainer-plugin-reinstall-${name}":
      path        => $exec_path,
      command     => "apptainer plugin install ${sif_path}",
      onlyif      => "apptainer plugin list | grep '${name}'",
      refreshonly => true,
      subscribe   => Exec["apptainer-plugin-compile-${name}"],
    }

    exec { "apptainer-plugin-enable-${name}":
      path    => $exec_path,
      command => "apptainer plugin enable ${name}",
      unless  => "apptainer plugin list | grep '${name}' | grep yes",
      require => [
        Exec["apptainer-plugin-install-${name}"],
        Exec["apptainer-plugin-reinstall-${name}"],
      ],
    }
  } else {
    exec { "apptainer-plugin-uninstall-${name}":
      path    => $exec_path,
      command => "apptainer plugin uninstall ${name}",
      onlyif  => "apptainer plugin list | grep '${name}'",
    }
  }

}