Defined Type: asdf::version

Defined in:
manifests/version.pp

Overview

Define version type for asdf

Parameters:

  • versions (Variant[String[1], Array[String[1], 1]])
  • ensure (Enum['present', 'absent']) (defaults to: 'present')
  • plugin (String[1]) (defaults to: $title)
  • global (Variant[String[1], Undef]) (defaults to: undef)


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

define asdf::version (
  Variant[String[1], Array[String[1], 1]] $versions,
  Enum['present', 'absent'] $ensure = 'present',
  String[1] $plugin = $title,
  Variant[String[1], Undef] $global = undef
) {
  $homedir = $facts['homedirs'][$asdf::owner]

  Exec {
    environment => ["HOME=${homedir}"],
    user        => $asdf::owner,
    group       => $asdf::group
  }

  $version_array = any2array($versions)

  if $global {
    $global_version = $global
  } else {
    $global_version = sort($version_array)[-1]
  }

  $bin = "${asdf::path}/bin/asdf"

  $version_array.each |String $version| {
    if $ensure == 'present' {
      exec { "${bin} install ${plugin} ${version}":
        unless  => "${bin} list ${plugin} | grep ${version}",
        timeout => 0,
        require => Asdf::Plugin[$plugin]
      }
    } else {
      exec { "${bin} uninstall ${plugin} ${version}":
        onlyif => "${bin} list ${plugin} | grep ${version}",
      }
    }
  }

  exec { "${bin} global ${plugin} ${global_version}":
    unless  => "${bin} current ${plugin} | grep ${global_version}",
    require => Exec["${bin} install ${plugin} ${global_version}"]
  }
}