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

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