From bc4295a33c4d2e1b958e3fbd38b4865b7e4db651 Mon Sep 17 00:00:00 2001 From: James Antill Date: Thu, 26 May 2022 00:51:24 -0400 Subject: [PATCH] Auto sync2gitlab import of ansible-collection-redhat-rhel_mgmt-1.0.0-2.el8.src.rpm --- .gitignore | 1 + EMPTY | 1 - ansible-collection-redhat-rhel_mgmt.spec | 137 +++++++++++++++++++++++ galaxy_transform.py | 24 ++++ sources | 1 + 5 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 .gitignore delete mode 100644 EMPTY create mode 100644 ansible-collection-redhat-rhel_mgmt.spec create mode 100755 galaxy_transform.py create mode 100644 sources diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..48724e3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/fedora.linux_mgmt-1.0.0.tar.gz diff --git a/EMPTY b/EMPTY deleted file mode 100644 index 0519ecb..0000000 --- a/EMPTY +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/ansible-collection-redhat-rhel_mgmt.spec b/ansible-collection-redhat-rhel_mgmt.spec new file mode 100644 index 0000000..1ff32f0 --- /dev/null +++ b/ansible-collection-redhat-rhel_mgmt.spec @@ -0,0 +1,137 @@ +%if 0%{?rhel} && ! 0%{?epel} +%bcond_with ansible +%else +%bcond_without ansible +%endif + +%bcond_with collection_artifact + +%global collection_namespace_orig fedora +%global collection_name_orig linux_mgmt + +%if 0%{?rhel} +%global collection_namespace redhat +%global collection_name rhel_mgmt +%else +%global collection_namespace %{collection_namespace_orig} +%global collection_name %{collection_name_orig} +%endif + +Name: ansible-collection-%{collection_namespace}-%{collection_name} +Url: https://github.com/pcahyna/fedora.linux_mgmt/ +Summary: Ansible Collection of general system management and utility modules and other plugins +Version: 1.0.0 +Release: 2%{?dist} + +License: GPLv3+ + +%global collection_version %{version} +%global archivename %{collection_namespace_orig}.%{collection_name_orig}-%{version} +%global extractdir %{archivename} + +# Helper macros originally from macros.ansible by Igor Raits +# Not available on RHEL, so we must define those macros locally here without using ansible-galaxy + +# Not used (yet). Could be made to point to AH in RHEL - but what about CentOS Stream? +#%%{!?ansible_collection_url:%%define ansible_collection_url() https://galaxy.ansible.com/%%{collection_namespace}/%%{collection_name}} + +%{!?ansible_collection_files:%define ansible_collection_files %{_datadir}/ansible/collections/ansible_collections/%{collection_namespace}} + +%if %{with ansible} +BuildRequires: ansible >= 2.9.10 +Requires: ansible >= 2.9.10 +%endif + +%if %{undefined ansible_collection_build} +%if %{without ansible} +# We don't have ansible-galaxy. +%define ansible_collection_build() tar -cf %{_tmppath}/%{collection_namespace}-%{collection_name}-%{version}.tar.gz . +%else +%define ansible_collection_build() ansible-galaxy collection build +%endif +%endif + +%if %{undefined ansible_collection_install} +%if %{without ansible} +# Simply copy everything instead of galaxy-installing the built artifact. +%define ansible_collection_install() mkdir -p %{buildroot}%{ansible_collection_files}/%{collection_name}; (cd %{buildroot}%{ansible_collection_files}/%{collection_name}; tar -xf %{_tmppath}/%{collection_namespace}-%{collection_name}-%{version}.tar.gz) +%else +%define ansible_collection_install() ansible-galaxy collection install -n -p %{buildroot}%{_datadir}/ansible/collections %{collection_namespace}-%{collection_name}-%{version}.tar.gz +%endif +%endif + +Source: https://github.com/pcahyna/fedora.linux_mgmt/archive/%{version}/%{archivename}.tar.gz + +BuildArch: noarch + +BuildRequires: python3 +BuildRequires: python3dist(ruamel.yaml) + +# utility for build +# originally from: https://github.com/linux-system-roles/auto-maintenance +# rev. 20d31bf5d8e7eb67ce48af39e36c9f79d87490e3 +# MIT license: https://github.com/linux-system-roles/auto-maintenance/blob/master/LICENSE +Source1: galaxy_transform.py + +%if %{undefined __ansible_provides} +Provides: ansible-collection(%{collection_namespace}.%{collection_name}) = %{collection_version} +%endif + +%description +%{summary}. +Targeted at GNU/Linux systems. + +%if %{with collection_artifact} +%package collection-artifact +Summary: Collection artifact to import to Automation Hub / Ansible Galaxy + +%description collection-artifact +Collection artifact for %{name}. This package contains %{collection_namespace}-%{collection_name}-%{version}.tar.gz +%endif + +%prep +%autosetup -n %{extractdir} + +# Replacing original (Galaxy) collection name by downstream (Automation Hub) name +%if "%{collection_namespace_orig}" != "%{collection_namespace}" || "%{collection_name_orig}" != "%{collection_name}" +find -type f -exec \ + sed "s/%{collection_namespace_orig}[.]%{collection_name_orig}/%{collection_namespace}.%{collection_name}/g" -i {} \; +%endif + +# borrowed from from ansible-collection-ansible-netcommon +find -type f ! -executable -type f -name '*.py' -print -exec sed -i -e '1{\@^#!.*@d}' '{}' + + +%{SOURCE1} %{collection_namespace} %{collection_name} %{collection_version} > galaxy.yml.new +mv galaxy.yml.new galaxy.yml + +%build +%ansible_collection_build + +%install +%ansible_collection_install + +%if %{with collection_artifact} +# Copy collection artifact to /usr/share/ansible/collections/ for collection-artifact +if [ -f %{collection_namespace}-%{collection_name}-%{version}.tar.gz ]; then + mv %{collection_namespace}-%{collection_name}-%{version}.tar.gz \ + $RPM_BUILD_ROOT%{_datadir}/ansible/collections/ +fi +%endif + +%files +%dir %{_datadir}/ansible +%license COPYING +%{ansible_collection_files} + +%if %{with collection_artifact} +%files collection-artifact +%{_datadir}/ansible/collections/%{collection_namespace}-%{collection_name}-%{version}.tar.gz +%endif + +%changelog +* Thu Aug 26 2021 Pavel Cahyna - 1.0.0-2 +- Create collection artifact subpackage, disabled by default + Taken from rhel-system-roles. + +* Thu Aug 05 2021 Pavel Cahyna - 1.0.0-1 +- Initial version diff --git a/galaxy_transform.py b/galaxy_transform.py new file mode 100755 index 0000000..3ba5e3d --- /dev/null +++ b/galaxy_transform.py @@ -0,0 +1,24 @@ +#!/usr/bin/python3 + +# Changes namespace, name, and version in Galaxy metadata. +# Useful for releasing to Automation Hub, where Collections live +# in namespaces separated from Ansible Galaxy. + +import sys +from ruamel.yaml import YAML + +filepath = "galaxy.yml" + +buf = open(filepath).read() + +yaml = YAML(typ="rt") +yaml.default_flow_style = False +yaml.preserve_quotes = True +yaml.indent(mapping=2, sequence=4, offset=2) + +code = yaml.load(buf) + +code["namespace"] = sys.argv[1] +code["name"] = sys.argv[2] +code["version"] = sys.argv[3] +yaml.dump(code, sys.stdout) diff --git a/sources b/sources new file mode 100644 index 0000000..c632031 --- /dev/null +++ b/sources @@ -0,0 +1 @@ +SHA512 (fedora.linux_mgmt-1.0.0.tar.gz) = b24b1e98bd21119f21d47ffcff47a3325cb0ab38ee5a7b241990fe28eb8b1146c0ae1b22cad3fa5c733f12950f4620bb690ebb03ca07b2b23cd34c63e6f06922