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