Puppet Class: golang

Defined in:
manifests/init.pp

Summary

Install Go

Overview

Download and install Go programming language

Examples:

include golang

Parameters:

  • version (String) (defaults to: '1.16.1')

    Version of Go to install

  • os (String[1]) (defaults to: downcase($facts['kernel']))

    The GOOS to install

  • arch (String[1]) (defaults to: $facts['os']['architecture'])

    The GOARCH to install

  • download_dir (Stdlib::Absolutepath) (defaults to: '/tmp')

    The directory of where to download Go

  • extract_dir (Stdlib::Absolutepath) (defaults to: '/opt')

    The directory where to extract Go

  • bin_dir (Stdlib::Absolutepath) (defaults to: '/usr/bin')

    The path to bin directory for go and gofmt symlinks



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

class golang (
  String $version = '1.16.1',
  String[1] $os = downcase($facts['kernel']),
  String[1] $arch = $facts['os']['architecture'],
  Stdlib::Absolutepath $download_dir = '/tmp',
  Stdlib::Absolutepath $extract_dir = '/opt',
  Stdlib::Absolutepath $bin_dir = '/usr/bin',
) {

  if $os != 'linux' {
    fail("Module golang only supports Linux, not ${os}")
  }

  case $arch {
    'x86_64', 'amd64': { $real_arch = 'amd64' }
    'i386':            { $real_arch = '386'   }
    'aarch64':         { $real_arch = 'arm64' }
    'armv7l':          { $real_arch = 'armv7' }
    'armv6l':          { $real_arch = 'armv6' }
    'armv5l':          { $real_arch = 'armv5' }
    default:           { $real_arch = $arch }
  }

  $file = "go${version}.${os}-${real_arch}.tar.gz"
  $install_dir = "${extract_dir}/go-${version}"

  file { $install_dir:
    ensure => 'directory',
    owner  => 'root',
    group  => 'root',
    mode   => '0755',
  }

  archive { "${download_dir}/${file}":
    source          => "https://dl.google.com/go/${file}",
    extract         => true,
    extract_path    => $install_dir,
    extract_command => 'tar xfz %s --strip-components=1',
    creates         => "${install_dir}/bin/go",
    cleanup         => true,
    user            => 'root',
    group           => 'root',
    require         => File[$install_dir],
    before          => [
      File['go-binary'],
      File['gofmt-binary'],
    ]
  }

  file { 'go-binary':
    ensure => 'link',
    path   => "${bin_dir}/go",
    target => "${install_dir}/bin/go",
  }
  file { 'gofmt-binary':
    ensure => 'link',
    path   => "${bin_dir}/gofmt",
    target => "${install_dir}/bin/gofmt",
  }
}