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
7accbc
%global collection_version_orig 1.0.0
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
7accbc
Version:        1.1.0
80eadb
Release:        2%{?dist}
80eadb
80eadb
License:        GPLv3+
80eadb
80eadb
%global collection_version %{version}
7accbc
%global archivename %{collection_namespace_orig}.%{collection_name_orig}-%{collection_version_orig}
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
7accbc
Source: https://github.com/pcahyna/fedora.linux_mgmt/archive/%{collection_version_orig}/%{archivename}.tar.gz
7accbc
7accbc
# Collection tarballs from Galaxy
7accbc
# Not used on Fedora.
7accbc
Source901: https://galaxy.ansible.com/download/community-general-5.4.0.tar.gz
7accbc
7accbc
Patch1: redfish-metadata.patch
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
7accbc
%if 0%{?rhel}
7accbc
%setup -T -a 901 -c -n .external/community/general
7accbc
%endif
7accbc
%setup -n %{extractdir}
7accbc
7accbc
%if 0%{?rhel}
7accbc
%patch1 -p1
7accbc
%endif
7accbc
7accbc
%if 0%{?rhel}
7accbc
modules=( remote_management/redfish/redfish_{command,config,info}.py )
7accbc
module_utils=( redfish_utils.py )
7accbc
7accbc
mkdir -p plugins/modules
7accbc
mkdir -p plugins/module_utils
7accbc
7accbc
for dir in %{_builddir}/.external/*/*; do
7accbc
    name=$(basename "$dir")
7accbc
    ns=$(basename $(dirname "$dir"))
7accbc
    for module in "${modules[@]}"; do
7accbc
        dest_module=plugins/modules/$(basename $module)
7accbc
        cp -pL $dir/plugins/modules/$module $dest_module
7accbc
        # Replacing original collection name by downstream (vendored) name
7accbc
        if [ "${ns}" != "%{collection_namespace}" ] || [ "${name}" != "%{collection_name}" ] ; then
7accbc
            sed "s/${ns}[.]${name}/%{collection_namespace}.%{collection_name}/g" -i $dest_module
7accbc
        fi
7accbc
    done
7accbc
    for module_util in "${module_utils[@]}"; do
7accbc
        dest_module_util=plugins/module_utils/$module_util
7accbc
        cp -pL $dir/plugins/module_utils/$module_util $dest_module_util
7accbc
        # Replacing original collection name by downstream (vendored) name
7accbc
        if [ "${ns}" != "%{collection_namespace}" ] || [ "${name}" != "%{collection_name}" ] ; then
7accbc
            sed "s/${ns}[.]${name}/%{collection_namespace}.%{collection_name}/g" -i $dest_module_util
7accbc
        fi
7accbc
    done
7accbc
done
7accbc
%endif
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
%build
7accbc
mkdir -p .collections/ansible_collections/%{collection_namespace}/%{collection_name}/
7accbc
cp -a * .collections/ansible_collections/%{collection_namespace}/%{collection_name}/
7accbc
%{SOURCE1} %{collection_namespace} %{collection_name} %{collection_version} > .collections/ansible_collections/%{collection_namespace}/%{collection_name}/galaxy.yml
7accbc
7accbc
pushd .collections/ansible_collections/%{collection_namespace}/%{collection_name}/
80eadb
%ansible_collection_build
7accbc
popd
80eadb
80eadb
%install
7accbc
pushd .collections/ansible_collections/%{collection_namespace}/%{collection_name}/
80eadb
%ansible_collection_install
7accbc
popd
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
7accbc
* Fri Aug 19 2022 Pavel Cahyna <pcahyna@redhat.com> - 1.1.0-2
7accbc
- Add redfish_* modules from community.general
7accbc
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