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

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