Blame SPECS/ansible-collection-redhat-rhel_mgmt.spec

ca98dd
%if 0%{?rhel} && ! 0%{?epel}
ca98dd
%bcond_with ansible
ca98dd
%else
ca98dd
%bcond_without ansible
ca98dd
%endif
ca98dd
ca98dd
%bcond_with collection_artifact
ca98dd
ca98dd
%global collection_namespace_orig fedora
ca98dd
%global collection_name_orig linux_mgmt
ca98dd
ca98dd
%if 0%{?rhel}
ca98dd
%global collection_namespace redhat
ca98dd
%global collection_name rhel_mgmt
ca98dd
%else
ca98dd
%global collection_namespace %{collection_namespace_orig}
ca98dd
%global collection_name %{collection_name_orig}
ca98dd
%endif
ca98dd
ca98dd
Name:           ansible-collection-%{collection_namespace}-%{collection_name}
ca98dd
Url:            https://github.com/pcahyna/fedora.linux_mgmt/
ca98dd
Summary:        Ansible Collection of general system management and utility modules and other plugins
ca98dd
Version:        1.0.0
ca98dd
Release:        2%{?dist}
ca98dd
ca98dd
License:        GPLv3+
ca98dd
ca98dd
%global collection_version %{version}
ca98dd
%global archivename %{collection_namespace_orig}.%{collection_name_orig}-%{version}
ca98dd
%global extractdir %{archivename}
ca98dd
ca98dd
# Helper macros originally from macros.ansible by Igor Raits <ignatenkobrain>
ca98dd
# Not available on RHEL, so we must define those macros locally here without using ansible-galaxy
ca98dd
ca98dd
# Not used (yet). Could be made to point to AH in RHEL - but what about CentOS Stream?
ca98dd
#%%{!?ansible_collection_url:%%define ansible_collection_url() https://galaxy.ansible.com/%%{collection_namespace}/%%{collection_name}}
ca98dd
ca98dd
%{!?ansible_collection_files:%define ansible_collection_files %{_datadir}/ansible/collections/ansible_collections/%{collection_namespace}}
ca98dd
ca98dd
%if %{with ansible}
ca98dd
BuildRequires: ansible >= 2.9.10
ca98dd
Requires: ansible >= 2.9.10
ca98dd
%endif
ca98dd
ca98dd
%if %{undefined ansible_collection_build}
ca98dd
%if %{without ansible}
ca98dd
# We don't have ansible-galaxy.
ca98dd
%define ansible_collection_build() tar -cf %{_tmppath}/%{collection_namespace}-%{collection_name}-%{version}.tar.gz .
ca98dd
%else
ca98dd
%define ansible_collection_build() ansible-galaxy collection build
ca98dd
%endif
ca98dd
%endif
ca98dd
ca98dd
%if %{undefined ansible_collection_install}
ca98dd
%if %{without ansible}
ca98dd
# Simply copy everything instead of galaxy-installing the built artifact.
ca98dd
%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)
ca98dd
%else
ca98dd
%define ansible_collection_install() ansible-galaxy collection install -n -p %{buildroot}%{_datadir}/ansible/collections %{collection_namespace}-%{collection_name}-%{version}.tar.gz
ca98dd
%endif
ca98dd
%endif
ca98dd
ca98dd
Source: https://github.com/pcahyna/fedora.linux_mgmt/archive/%{version}/%{archivename}.tar.gz
ca98dd
ca98dd
BuildArch: noarch
ca98dd
ca98dd
BuildRequires: python3
ca98dd
BuildRequires: python3dist(ruamel.yaml)
ca98dd
ca98dd
# utility for build
ca98dd
# originally from: https://github.com/linux-system-roles/auto-maintenance
ca98dd
# rev. 20d31bf5d8e7eb67ce48af39e36c9f79d87490e3
ca98dd
# MIT license: https://github.com/linux-system-roles/auto-maintenance/blob/master/LICENSE
ca98dd
Source1: galaxy_transform.py
ca98dd
ca98dd
%if %{undefined __ansible_provides}
ca98dd
Provides: ansible-collection(%{collection_namespace}.%{collection_name}) = %{collection_version}
ca98dd
%endif
ca98dd
ca98dd
%description
ca98dd
%{summary}.
ca98dd
Targeted at GNU/Linux systems.
ca98dd
ca98dd
%if %{with collection_artifact}
ca98dd
%package collection-artifact
ca98dd
Summary: Collection artifact to import to Automation Hub / Ansible Galaxy
ca98dd
ca98dd
%description collection-artifact
ca98dd
Collection artifact for %{name}. This package contains %{collection_namespace}-%{collection_name}-%{version}.tar.gz
ca98dd
%endif
ca98dd
ca98dd
%prep
ca98dd
%autosetup -n %{extractdir}
ca98dd
ca98dd
# Replacing original (Galaxy) collection name by downstream (Automation Hub) name
ca98dd
%if "%{collection_namespace_orig}" != "%{collection_namespace}" || "%{collection_name_orig}" != "%{collection_name}"
ca98dd
find -type f -exec \
ca98dd
    sed "s/%{collection_namespace_orig}[.]%{collection_name_orig}/%{collection_namespace}.%{collection_name}/g" -i {} \;
ca98dd
%endif
ca98dd
ca98dd
# borrowed from from ansible-collection-ansible-netcommon
ca98dd
find -type f ! -executable -type f -name '*.py' -print -exec sed -i -e '1{\@^#!.*@d}' '{}' +
ca98dd
ca98dd
%{SOURCE1} %{collection_namespace} %{collection_name} %{collection_version} > galaxy.yml.new
ca98dd
mv galaxy.yml.new galaxy.yml
ca98dd
ca98dd
%build
ca98dd
%ansible_collection_build
ca98dd
ca98dd
%install
ca98dd
%ansible_collection_install
ca98dd
ca98dd
%if %{with collection_artifact}
ca98dd
# Copy collection artifact to /usr/share/ansible/collections/ for collection-artifact
ca98dd
if [ -f %{collection_namespace}-%{collection_name}-%{version}.tar.gz ]; then
ca98dd
    mv %{collection_namespace}-%{collection_name}-%{version}.tar.gz \
ca98dd
       $RPM_BUILD_ROOT%{_datadir}/ansible/collections/
ca98dd
fi
ca98dd
%endif
ca98dd
ca98dd
%files
ca98dd
%dir %{_datadir}/ansible
ca98dd
%license COPYING
ca98dd
%{ansible_collection_files}
ca98dd
ca98dd
%if %{with collection_artifact}
ca98dd
%files collection-artifact
ca98dd
%{_datadir}/ansible/collections/%{collection_namespace}-%{collection_name}-%{version}.tar.gz
ca98dd
%endif
ca98dd
ca98dd
%changelog
ca98dd
* Thu Aug 26 2021 Pavel Cahyna <pcahyna@redhat.com> - 1.0.0-2
ca98dd
- Create collection artifact subpackage, disabled by default
ca98dd
  Taken from rhel-system-roles.
ca98dd
ca98dd
* Thu Aug 05 2021 Pavel Cahyna <pcahyna@redhat.com> - 1.0.0-1
ca98dd
- Initial version