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]
}
}
}
|