Defined Type: quadlets::quadlet

Defined in:
manifests/quadlet.pp

Summary

Generate and manage podman quadlet definitions (podman > 4.4.0)

Overview

Examples:

Run a CentOS Container

quadlets::quadlet{'centos.container':
  ensure          => present,
  unit_entry     => {
   'Description' => 'Trivial Container that will be very lazy',
  },
  service_entry       => {
    'TimeoutStartSec' => '900',
  },
  container_entry => {
    'Image' => 'quay.io/centos/centos:latest',
    'Exec'  => 'sh -c "sleep inf"'
  },
  install_entry   => {
    'WantedBy' => 'default.target'
  },
  active          => true,
}

Run a Pod using a kubernetes Yaml definition

quadlets::quadlet{'centos.container':
  ensure          => present,
  unit_entry     => {
   'Description' => 'Pod running my application',
  },
  kube_entry => {
    'Yaml' => '/path/to/yaml/file.yaml',
  },
  install_entry   => {
    'WantedBy' => 'default.target'
  },
  active          => true,
}

Parameters:

  • quadlet (Quadlets::Quadlet_name) (defaults to: $title)

    of the quadlet file this is the namevar.

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

    State of the container definition.

  • mode (Stdlib::Filemode) (defaults to: '0444')

    Filemode of container file.

  • active (Optional[Boolean]) (defaults to: undef)

    Make sure the container is running.

  • unit_entry (Optional[Systemd::Unit::Unit]) (defaults to: undef)

    The ‘[Unit]` section definition.

  • install_entry (Optional[Systemd::Unit::Install]) (defaults to: undef)

    The ‘[Install]` section definition.

  • service_entry (Optional[Systemd::Unit::Service]) (defaults to: undef)

    The ‘[Service]` section definition.

  • container_entry (Optional[Quadlets::Unit::Container]) (defaults to: undef)

    The ‘[Container]` section defintion.

  • pod_entry (Optional[Quadlets::Unit::Pod]) (defaults to: undef)

    The ‘[Pod]` section defintion.

  • volume_entry (Optional[Quadlets::Unit::Volume]) (defaults to: undef)

    The ‘[Volume]` section defintion.

  • kube_entry (Optional[Quadlets::Unit::Kube]) (defaults to: undef)

    The ‘[Kube]` section defintion.

See Also:

  • https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html


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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'manifests/quadlet.pp', line 51

define quadlets::quadlet (
  Enum['present', 'absent'] $ensure = 'present',
  Quadlets::Quadlet_name $quadlet = $title,
  Stdlib::Filemode $mode = '0444',
  Optional[Boolean] $active = undef,
  Optional[Systemd::Unit::Install] $install_entry = undef,
  Optional[Systemd::Unit::Unit] $unit_entry = undef,
  Optional[Systemd::Unit::Service] $service_entry = undef,
  Optional[Quadlets::Unit::Container] $container_entry = undef,
  Optional[Quadlets::Unit::Volume] $volume_entry = undef,
  Optional[Quadlets::Unit::Pod] $pod_entry = undef,
  Optional[Quadlets::Unit::Kube] $kube_entry = undef,
) {
  $_split = $quadlet.split('[.]')
  $_name = $_split[0]
  $_type = $_split[1]
  # Validate the input and find the service name.
  case $_type {
    'container': {
      if $volume_entry or $pod_entry {
        fail('A volume_entry or pod_entry makes no sense on a container quadlet')
      }
      $_service = "${_name}.service"
    }
    'volume': {
      if $container_entry or $pod_entry or $kube_entry {
        fail('A container_entry, pod_entry or kube_entry makes no sense on a volume quadlet')
      }
      $_service = "${_name}-volume.service"
    }
    'pod': {
      if $container_entry or $volume_entry or $kube_entry {
        fail('A container_entry, volume_entry or kube_entry makes no sense on a pod quadlet')
      }
      $_service = "${_name}-pod.service"
    }
    'kube': {
      if $volume_entry or $pod_entry or $container_entry {
        fail('A container_entry, pod_entry or volume_entry makes no sense on a kube quadlet')
      }
      $_service = "${_name}.service"
    }
    default: {
      fail('Should never be here due to typing on quadlet')
    }
  }

  include quadlets

  file { "${quadlets::quadlet_dir}/${quadlet}":
    ensure  => $ensure,
    owner   => 'root',
    group   => 'root',
    mode    => $mode,
    content => epp('quadlets/quadlet_file.epp', {
        'unit_entry'      => $unit_entry,
        'service_entry'   => $service_entry,
        'install_entry'   => $install_entry,
        'container_entry' => $container_entry,
        'volume_entry'    => $volume_entry,
        'pod_entry'       => $pod_entry,
        'kube_entry'      => $kube_entry,
    }),
  }

  ensure_resource('systemd::daemon_reload', $quadlet)
  File["${quadlets::quadlet_dir}/${quadlet}"] ~> Systemd::Daemon_reload[$quadlet]

  if $active != undef {
    service { $_service:
      ensure => $active,
    }

    if $ensure == 'absent' {
      Service[$_service] -> File["${quadlets::quadlet_dir}/${quadlet}"]
      File["${quadlets::quadlet_dir}/${quadlet}"] ~> Systemd::Daemon_reload[$quadlet]
    } else {
      File["${quadlets::quadlet_dir}/${quadlet}"] ~> Service[$_service]
      Systemd::Daemon_reload[$quadlet] ~> Service[$_service]
    }
  }
}