Fix inverted conditionals and BR: ansible-packaging

Fix and simply inverted conditionals and build/install the collection
using ansible-galaxy. Previously, the conditionals were inverted and the
%ansible_collection_* macros weren't used on Fedora, instead using the
tar hack meant for RHEL 8. BR: ansible-packaging is needed for these
macros.
This commit is contained in:
Maxwell G 2022-11-19 14:18:19 -06:00
parent d1ababd8b2
commit 783912e31e
No known key found for this signature in database
GPG Key ID: F79E4E25E8C661F8

View File

@ -8,9 +8,10 @@ Source: https://github.com/performancecopilot/ansible-pcp/archive/v%{v
Patch0: 0001-build_ignore-unnecessary-files.patch Patch0: 0001-build_ignore-unnecessary-files.patch
BuildArch: noarch BuildArch: noarch
%if 0%{?rhel} %if %{defined rhel}
%global collection_namespace redhat %global collection_namespace redhat
%global collection_name rhel_metrics %global collection_name rhel_metrics
%global ansible_collection_files %{_datadir}/ansible/collections/ansible_collections/%{collection_namespace}
%else %else
%global collection_namespace performancecopilot %global collection_namespace performancecopilot
%global collection_name metrics %global collection_name metrics
@ -20,36 +21,17 @@ BuildArch: noarch
Requires: (ansible-core >= 2.11.0 or ansible >= 2.9.0) Requires: (ansible-core >= 2.11.0 or ansible >= 2.9.0)
%endif %endif
# NOTE: Even though ansible-core is in 8.6, it is only available
# at *runtime*, not at *buildtime* - so we can't have
# ansible-core as a build_dep on RHEL8
%if 0%{?fedora} || 0%{?rhel} >= 9
%global have_ansible 0
%global ansible_build_dep ansible-core >= 2.11.0
%else
%if 0%{?rhel} && ! 0%{?epel}
%global have_ansible 1
%else
%global have_ansible 0
%global ansible_build_dep ansible >= 2.9.10
%endif
%endif
%if %{have_ansible}
BuildRequires: %{ansible_build_dep}
# package has been removed from RHEL9
%if 0%{?rhel} >= 9 %if 0%{?rhel} >= 9
%global have_ansible_lint 0 BuildRequires: ansible-core
%else %global ansible_collection_build ansible-galaxy collection build .
%global have_ansible_lint 1 %global ansible_collection_install ansible-galaxy collection install -n -p %{buildroot}%{_datadir}/ansible/collections %{collection_namespace}-%{collection_name}-%{version}.tar.gz
%endif
%else
%global have_ansible_lint 0
%global ansible_collection_files %{_datadir}/ansible/collections/ansible_collections/%{collection_namespace}
%endif %endif
%if %{have_ansible_lint} %if %{defined fedora}
BuildRequires: python3-ansible-lint BuildRequires: ansible-packaging
BuildRequires: ansible-packaging-tests
# There's ansible-lint errors that need to be addressed
# BuildRequires: python3-ansible-lint
%endif %endif
%description %description
@ -103,19 +85,22 @@ find . -name \*.yml -o -name \*.md | while read file; do
done done
%build %build
%if %{have_ansible} # NOTE: Even though ansible-core is in 8.6, it is only available
%ansible_collection_build # at *runtime*, not at *buildtime* - so we can't have
%else # ansible-core as a build_dep on RHEL8
%if %{defined rhel} && 0%{?rhel} <= 8
tar -cf %{_tmppath}/%{collection_namespace}-%{collection_name}-%{version}.tar.gz . tar -cf %{_tmppath}/%{collection_namespace}-%{collection_name}-%{version}.tar.gz .
%else
%ansible_collection_build
%endif %endif
%install %install
%if %{have_ansible} %if %{defined rhel} && 0%{?rhel} <= 8
%ansible_collection_install
%else
mkdir -p %{buildroot}%{ansible_collection_files}/%{collection_name} mkdir -p %{buildroot}%{ansible_collection_files}/%{collection_name}
cd %{buildroot}%{ansible_collection_files}/%{collection_name} cd %{buildroot}%{ansible_collection_files}/%{collection_name}
tar -xf %{_tmppath}/%{collection_namespace}-%{collection_name}-%{version}.tar.gz tar -xf %{_tmppath}/%{collection_namespace}-%{collection_name}-%{version}.tar.gz
%else
%ansible_collection_install
%endif %endif
%check %check