diff --git a/cobbler/package/clean.sls b/cobbler/package/clean.sls index 60d84f33..b952d78f 100644 --- a/cobbler/package/clean.sls +++ b/cobbler/package/clean.sls @@ -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 }} diff --git a/cobbler/package/init.sls b/cobbler/package/init.sls index d3e55181..16df99d4 100644 --- a/cobbler/package/init.sls +++ b/cobbler/package/init.sls @@ -3,3 +3,4 @@ include: - .install + - .repository diff --git a/cobbler/package/install.sls b/cobbler/package/install.sls index 9a249d3a..ab487f48 100644 --- a/cobbler/package/install.sls +++ b/cobbler/package/install.sls @@ -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 %} diff --git a/cobbler/package/repository.sls b/cobbler/package/repository.sls new file mode 100644 index 00000000..a43bce94 --- /dev/null +++ b/cobbler/package/repository.sls @@ -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 %} diff --git a/cobbler/parameters/defaults.yaml b/cobbler/parameters/defaults.yaml index ceac7baa..d2c28d82 100644 --- a/cobbler/parameters/defaults.yaml +++ b/cobbler/parameters/defaults.yaml @@ -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' diff --git a/cobbler/parameters/os/Fedora.yaml b/cobbler/parameters/os/Fedora.yaml index 322dd364..910df1c1 100644 --- a/cobbler/parameters/os/Fedora.yaml +++ b/cobbler/parameters/os/Fedora.yaml @@ -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 ... diff --git a/cobbler/parameters/os_family/Debian.yaml b/cobbler/parameters/os_family/Debian.yaml index 0d579c7a..bae297c8 100644 --- a/cobbler/parameters/os_family/Debian.yaml +++ b/cobbler/parameters/os_family/Debian.yaml @@ -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 ... diff --git a/cobbler/parameters/os_family/RedHat.yaml b/cobbler/parameters/os_family/RedHat.yaml index 350d5658..01067622 100644 --- a/cobbler/parameters/os_family/RedHat.yaml +++ b/cobbler/parameters/os_family/RedHat.yaml @@ -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 ... diff --git a/cobbler/parameters/osfinger/AlmaLinux-8.yaml b/cobbler/parameters/osfinger/AlmaLinux-8.yaml new file mode 100644 index 00000000..5c9dcd03 --- /dev/null +++ b/cobbler/parameters/osfinger/AlmaLinux-8.yaml @@ -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 +... diff --git a/cobbler/parameters/osfinger/AlmaLinux-9.yaml b/cobbler/parameters/osfinger/AlmaLinux-9.yaml new file mode 100644 index 00000000..3d29e2dc --- /dev/null +++ b/cobbler/parameters/osfinger/AlmaLinux-9.yaml @@ -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 +... diff --git a/cobbler/parameters/osfinger/CentOS Stream-8.yaml b/cobbler/parameters/osfinger/CentOS Stream-8.yaml new file mode 100644 index 00000000..fbdf5b71 --- /dev/null +++ b/cobbler/parameters/osfinger/CentOS Stream-8.yaml @@ -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 +... diff --git a/cobbler/parameters/osfinger/CentOS Stream-9.yaml b/cobbler/parameters/osfinger/CentOS Stream-9.yaml new file mode 100644 index 00000000..60aa382b --- /dev/null +++ b/cobbler/parameters/osfinger/CentOS Stream-9.yaml @@ -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 +... diff --git a/cobbler/parameters/osfinger/Rocky Linux-8.yaml b/cobbler/parameters/osfinger/Rocky Linux-8.yaml new file mode 100644 index 00000000..82d3c1b8 --- /dev/null +++ b/cobbler/parameters/osfinger/Rocky Linux-8.yaml @@ -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 +... diff --git a/cobbler/parameters/osfinger/Rocky Linux-9.yaml b/cobbler/parameters/osfinger/Rocky Linux-9.yaml new file mode 100644 index 00000000..3c46a5de --- /dev/null +++ b/cobbler/parameters/osfinger/Rocky Linux-9.yaml @@ -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 +... diff --git a/kitchen.yml b/kitchen.yml index 2e2e595a..dd08ab15 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -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 diff --git a/test/integration/default/controls/config.rb b/test/integration/default/controls/config.rb index 0de5966d..afa5dde8 100644 --- a/test/integration/default/controls/config.rb +++ b/test/integration/default/controls/config.rb @@ -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 diff --git a/test/integration/default/controls/packages.rb b/test/integration/default/controls/packages.rb index 8c944a1b..d79f20be 100644 --- a/test/integration/default/controls/packages.rb +++ b/test/integration/default/controls/packages.rb @@ -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 diff --git a/test/integration/default/files/_mapdata/almalinux-8.yaml b/test/integration/default/files/_mapdata/almalinux-8.yaml index dd316399..2005f879 100644 --- a/test/integration/default/files/_mapdata/almalinux-8.yaml +++ b/test/integration/default/files/_mapdata/almalinux-8.yaml @@ -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 diff --git a/test/integration/default/files/_mapdata/centos-8.yaml b/test/integration/default/files/_mapdata/centos-8.yaml index 210d204f..ad7d16fa 100644 --- a/test/integration/default/files/_mapdata/centos-8.yaml +++ b/test/integration/default/files/_mapdata/centos-8.yaml @@ -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 diff --git a/test/integration/default/files/_mapdata/debian-11.yaml b/test/integration/default/files/_mapdata/debian-11.yaml index a147b9a2..b5223f9d 100644 --- a/test/integration/default/files/_mapdata/debian-11.yaml +++ b/test/integration/default/files/_mapdata/debian-11.yaml @@ -22,7 +22,15 @@ values: - Y:G@id master: template-master pkg: - name: bash + communityrepo: + enabled: true + version: "3.3.x" + epel: + enabled: false + name: cobbler + source: + enabled: false + version: "main" rootgroup: root service: name: systemd-journald diff --git a/test/integration/default/files/_mapdata/fedora-36.yaml b/test/integration/default/files/_mapdata/fedora-36.yaml index 30b64823..e5626d09 100644 --- a/test/integration/default/files/_mapdata/fedora-36.yaml +++ b/test/integration/default/files/_mapdata/fedora-36.yaml @@ -22,7 +22,15 @@ values: - Y:G@id master: template-master pkg: - name: bash + communityrepo: + enabled: false + version: 3.3.x + epel: + enabled: false + name: cobbler + source: + enabled: false + version: main rootgroup: root service: name: systemd-journald diff --git a/test/integration/default/files/_mapdata/opensuse-15.yaml b/test/integration/default/files/_mapdata/opensuse-15.yaml index 28de5a98..a552432b 100644 --- a/test/integration/default/files/_mapdata/opensuse-15.yaml +++ b/test/integration/default/files/_mapdata/opensuse-15.yaml @@ -22,7 +22,15 @@ values: - Y:G@id master: template-master pkg: - name: bash + communityrepo: + enabled: false + version: 3.3.x + epel: + enabled: false + name: cobbler + source: + enabled: false + version: main rootgroup: root service: name: systemd-journald diff --git a/test/integration/default/files/_mapdata/opensuse-tumbleweed.yaml b/test/integration/default/files/_mapdata/opensuse-tumbleweed.yaml index d3e7fbb3..409896c9 100644 --- a/test/integration/default/files/_mapdata/opensuse-tumbleweed.yaml +++ b/test/integration/default/files/_mapdata/opensuse-tumbleweed.yaml @@ -22,7 +22,15 @@ values: - Y:G@id master: template-master pkg: - name: bash + communityrepo: + enabled: false + version: 3.3.x + epel: + enabled: false + name: cobbler + source: + enabled: false + version: main rootgroup: root service: name: systemd-journald diff --git a/test/integration/default/files/_mapdata/rockylinux-8.yaml b/test/integration/default/files/_mapdata/rockylinux-8.yaml index 7be6b399..8fb67724 100644 --- a/test/integration/default/files/_mapdata/rockylinux-8.yaml +++ b/test/integration/default/files/_mapdata/rockylinux-8.yaml @@ -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 diff --git a/test/integration/default/files/_mapdata/ubuntu-22.yaml b/test/integration/default/files/_mapdata/ubuntu-22.yaml index 4f0e50df..88c29bb8 100644 --- a/test/integration/default/files/_mapdata/ubuntu-22.yaml +++ b/test/integration/default/files/_mapdata/ubuntu-22.yaml @@ -22,7 +22,15 @@ values: - Y:G@id master: template-master pkg: - name: bash + communityrepo: + enabled: true + version: 3.3.x + epel: + enabled: false + name: cobbler + source: + enabled: false + version: main rootgroup: root service: name: systemd-journald diff --git a/test/salt/pillar/default.sls b/test/salt/pillar/default.sls index 6748ec17..139fd6cd 100644 --- a/test/salt/pillar/default.sls +++ b/test/salt/pillar/default.sls @@ -8,11 +8,6 @@ cobbler: winner: lookup added_in_lookup: lookup_value - # Using bash package and udev service as an example. This allows us to - # test the template formula itself. You should set these parameters to - # examples that make sense in the contexto of the formula you're writing. - pkg: - name: bash service: name: systemd-journald config: /etc/template-formula.conf