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

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