Skip to content

Commit

Permalink
feat(formula): install Cobbler from OS, community or epel
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoolGuy committed Nov 17, 2023
1 parent 2993d7a commit d5d167c
Show file tree
Hide file tree
Showing 26 changed files with 361 additions and 21 deletions.
6 changes: 6 additions & 0 deletions cobbler/package/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
include:
- {{ sls_config_clean }}
{% if pkg.communityrepo.enabled %}
cobbler-package-clean-repository-removed:
pkgrepo.absent:
- name: cobbler_community_repo
{% endif %}
cobbler-package-clean-pkg-removed:
pkg.removed:
- name: {{ cobbler.pkg.name }}
Expand Down
1 change: 1 addition & 0 deletions cobbler/package/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

include:
- .install
- .repository
23 changes: 22 additions & 1 deletion cobbler/package/install.sls
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,28 @@
{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import mapdata as cobbler with context %}
{%- set sls_repo_available = tplroot ~ '.package.repository' %}
{%- if cobbler.pkg.epel.enabled %}
include:
- epel
{%- if grains["osfinger"] == "CentOS Linux-8" %}
cobbler-package-install-pkg-enable-dnf-module:
cmd.run:
- name: dnf module enable cobbler
- unless: dnf module list --enabled | grep cobbler
- require:
- pkg: epel_release
{%- endif %}
{%- endif %}
cobbler-package-install-pkg-installed:
pkg.installed:
- name: {{ cobbler.pkg.name }}
{%- if cobbler.pkg.communityrepo.enabled %}
- require:
- sls: {{ sls_repo_available }}
{%- elif cobbler.pkg.epel.enabled %}
# Isn't supported by the yum backend of Salt. We are using osfinger parameter files to fix this. :(
# - resolve_capabilities: true
- require:
- pkg: epel_release
{%- endif %}
124 changes: 124 additions & 0 deletions cobbler/package/repository.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# -*- coding: utf-8 -*-
# vim: ft=sls

# Cobbler 3.4.x - https://build.opensuse.org/project/show/systemsmanagement:cobbler:release34
# Cobbler 3.3.x - https://build.opensuse.org/project/show/systemsmanagement:cobbler:release33
# Cobbler 3.2.x - https://build.opensuse.org/project/show/systemsmanagement:cobbler:release32
# Cobbler 3.1.x - https://build.opensuse.org/project/show/systemsmanagement:cobbler:release31
# Cobbler 3.0.x - https://build.opensuse.org/project/show/systemsmanagement:cobbler:release30
# Cobbler 2.8.x - https://build.opensuse.org/project/show/systemsmanagement:cobbler:release28
# Cobbler 2.6.x - https://build.opensuse.org/project/show/systemsmanagement:cobbler:release26
# Cobbler 2.4.x - https://build.opensuse.org/project/show/systemsmanagement:cobbler:release24

{#- Get the `tplroot` from `tpldir` #}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import mapdata as cobbler with context %}
{%- set repo_version = {
"3.4.x": "release34",
"3.3.x": "release33",
"3.2.x": "release32",
"3.1.x": "release31",
"3.0.x": "release30",
"2.8.x": "release28",
"2.6.x": "release26",
"2.4.x": "release24",
}.get(cobbler.pkg.communityrepo.version) %}
{%- set repo_os_name = {
"3.4.x": {},
"3.3.x": {
"openSUSE Tumbleweed": {
"": "openSUSE_Tumbleweed"
},
"Leap": {
"15.3": "Leap_15.3",
"15.4": "Leap_15.4",
},
"SLES": {},
"Fedora": {
"34": "Fedora_34",
},
"CentOS": {
"8": "CentOS_8",
},
"CentOS Stream": {},
"Debian": {
"10": "Debian_10",
"11": "Debian_11",
},
"Ubuntu": {
"18.04": "xUbuntu_18.04",
"20.04": "xUbuntu_20.04",
"22.04": "xUbuntu_22.04",
},
},
"3.2.x": {
"Leap": {
"15.2": "Leap_15.2",
},
"SLES": {
"15.1": "SLE_15_SP1",
},
"Fedora": {
"31": "Fedora_31",
},
"CentOS": {},
"CentOS Stream": {
"8": "CentOS_8_Stream",
},
"Debian": {
"10": "Debian_10",
},
"Ubuntu": {
"18.04": "xUbuntu_18.04",
},
},
"3.1.x": {},
"3.0.x": {
"Fedora": {
"29": "Fedora_29",
},
},
"2.8.x": {},
"2.6.x": {},
"2.4.x": {},
} %}
{%- set repo_os_releases = repo_os_name.get(cobbler.pkg.communityrepo.version).get(grains["os"]) %}
{% if cobbler.pkg.communityrepo.enabled %}
{% if repo_os_releases is not none and repo_os_releases.get(grains["osrelease"]) is not none %}
{%- set repo_os_name_lookup = repo_os_releases.get(grains["osrelease"]) %}
cobbler-package-install-repo-available:
pkgrepo.managed:
{% if grains["os_family"] == "Debian" %}
- name: deb http://download.opensuse.org/repositories/systemsmanagement:/cobbler:/{{ repo_version }}/{{ repo_os_name_lookup }}/ /
- key_url: https://download.opensuse.org/repositories/systemsmanagement:/cobbler:/{{ repo_version }}/{{ repo_os_name_lookup }}/Release.key
{% elif grains["os_family"] in ("RedHat", "Suse") %}
- name: cobbler_community_repo
{% endif %}
- gpgcheck: true
- gpgkey: true
- gpgautoimport: true
- humanname: Cobbler Community OBS repository
{% if grains["os_family"] in ("RedHat", "Suse") %}
- baseurl: https://download.opensuse.org/repositories/systemsmanagement:/cobbler:{{ repo_version }}/{{ repo_os_name_lookup }}/
{% endif %}
{% else %}
cobbler-package-install-repo-unavailable:
test.fail_without_changes:
- name: |
################################################################################
# #
# WARNING: Requested OS and Cobbler version not compatible #
# #
################################################################################
# #
# The Cobbler community repositories are maintained by volunteers that have #
# limited time. The OS and requested Cobbler version are at the moment not #
# available. Please either request this new combination on GitHub #
# (https://github.com/cobbler/cobbler/issues/) or switch to another OS and #
# Cobbler combination! #
# #
################################################################################
Please include the following information in the issue:
{{ cobbler.pkg.communityrepo.version }}/{{ grains["os"] }}/{{ grains["osrelease"] }}
{% endif %}
{% endif %}
11 changes: 11 additions & 0 deletions cobbler/parameters/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
---
values:
pkg:
source:
enabled: false
version: "main"
communityrepo:
# This is mutually exclusive with "epel"!
enabled: false
# Available: "2.4.x", "2.6.x", "2.8.x", "3.0.x", "3.1.x", "3.2.x", "3.3.x"
version: "3.3.x"
epel:
# This is mutually exclusive with "communityrepo"!
enabled: false
name: cobbler
rootgroup: root
config: '/etc/cobbler'
Expand Down
6 changes: 5 additions & 1 deletion cobbler/parameters/os/Fedora.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@
# you can remove this file or provide at least an empty dict, e.g.
# values: {}
---
values: {}
values:
pkg:
epel:
# Reset to false since Cobbler is in Fedora
enabled: false
...
5 changes: 4 additions & 1 deletion cobbler/parameters/os_family/Debian.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
# you can remove this file or provide at least an empty dict, e.g.
# values: {}
---
values: {}
values:
pkg:
communityrepo:
enabled: true
...
5 changes: 4 additions & 1 deletion cobbler/parameters/os_family/RedHat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
# you can remove this file or provide at least an empty dict, e.g.
# values: {}
---
values: {}
values:
pkg:
epel:
enabled: true
...
17 changes: 17 additions & 0 deletions cobbler/parameters/osfinger/AlmaLinux-8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
#
# Set values specific to:
# salt['config.get']('osfinger') == AlmaLinux-8.
#
# You just need to add the key:values for this `osfinger` that differ
# from `defaults.yaml`.
#
# If you do not need to provide defaults via the `osfinger` config,
# you can remove this file or provide at least an empty dict, e.g.
# values: {}
---
values:
pkg:
name: cobbler3.2
...
17 changes: 17 additions & 0 deletions cobbler/parameters/osfinger/AlmaLinux-9.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
#
# Set values specific to:
# salt['config.get']('osfinger') == AlmaLinux-9.
#
# You just need to add the key:values for this `osfinger` that differ
# from `defaults.yaml`.
#
# If you do not need to provide defaults via the `osfinger` config,
# you can remove this file or provide at least an empty dict, e.g.
# values: {}
---
values:
pkg:
name: cobbler3.3
...
17 changes: 17 additions & 0 deletions cobbler/parameters/osfinger/CentOS Stream-8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
#
# Set values specific to:
# salt['config.get']('osfinger') == CentOS Stream-8.
#
# You just need to add the key:values for this `osfinger` that differ
# from `defaults.yaml`.
#
# If you do not need to provide defaults via the `osfinger` config,
# you can remove this file or provide at least an empty dict, e.g.
# values: {}
---
values:
pkg:
name: cobbler3.2
...
17 changes: 17 additions & 0 deletions cobbler/parameters/osfinger/CentOS Stream-9.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
#
# Set values specific to:
# salt['config.get']('osfinger') == CentOS Stream-9.
#
# You just need to add the key:values for this `osfinger` that differ
# from `defaults.yaml`.
#
# If you do not need to provide defaults via the `osfinger` config,
# you can remove this file or provide at least an empty dict, e.g.
# values: {}
---
values:
pkg:
name: cobbler3.3
...
17 changes: 17 additions & 0 deletions cobbler/parameters/osfinger/Rocky Linux-8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
#
# Set values specific to:
# salt['config.get']('osfinger') == Rocky Linux-8.
#
# You just need to add the key:values for this `osfinger` that differ
# from `defaults.yaml`.
#
# If you do not need to provide defaults via the `osfinger` config,
# you can remove this file or provide at least an empty dict, e.g.
# values: {}
---
values:
pkg:
name: cobbler3.2
...
17 changes: 17 additions & 0 deletions cobbler/parameters/osfinger/Rocky Linux-9.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# vim: ft=yaml
#
# Set values specific to:
# salt['config.get']('osfinger') == Rocky Linux-9.
#
# You just need to add the key:values for this `osfinger` that differ
# from `defaults.yaml`.
#
# If you do not need to provide defaults via the `osfinger` config,
# you can remove this file or provide at least an empty dict, e.g.
# values: {}
---
values:
pkg:
name: cobbler3.3
...
4 changes: 4 additions & 0 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ provisioner:
salt_install: none
require_chef: false
formula: cobbler
dependencies:
- name: epel
repo: git
source: https://github.com/saltstack-formulas/epel-formula.git
salt_copy_filter:
- .kitchen
- .git
Expand Down
2 changes: 1 addition & 1 deletion test/integration/default/controls/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
its('content') { should include '"added_in_lookup": "lookup_value"' }
its('content') { should include '"config": "/etc/template-formula.conf"' }
its('content') { should include '"lookup": {"added_in_lookup": "lookup_value",' }
its('content') { should include '"pkg": {"name": "' }
its('content') { should include '"pkg": {"communityrepo": {' }
its('content') { should include '"service": {"name": "' }
its('content') do
# rubocop:disable Lint/RedundantCopDisableDirective
Expand Down
8 changes: 5 additions & 3 deletions test/integration/default/controls/packages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
# Override by `platform_finger`
package_name =
case platform_finger
when 'centos-6', 'amazonlinux-1'
'cronie'
when 'centos-8', 'rockylinux-8', 'almalinux-8'
'cobbler3.2'
when 'centos-9', 'rockylinux-9', 'almalinux-9'
'cobbler3.3'
else
'bash'
'cobbler'
end

describe package(package_name) do
Expand Down
10 changes: 9 additions & 1 deletion test/integration/default/files/_mapdata/almalinux-8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ values:
- Y:G@id
master: template-master
pkg:
name: bash
communityrepo:
enabled: false
version: 3.3.x
epel:
enabled: true
name: cobbler3.2
source:
enabled: false
version: main
rootgroup: root
service:
name: systemd-journald
Expand Down
10 changes: 9 additions & 1 deletion test/integration/default/files/_mapdata/centos-8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ values:
- Y:G@id
master: template-master
pkg:
name: bash
communityrepo:
enabled: false
version: 3.3.x
epel:
enabled: true
name: cobbler3.2
source:
enabled: false
version: main
rootgroup: root
service:
name: systemd-journald
Expand Down
Loading

0 comments on commit d5d167c

Please sign in to comment.