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