%global with_docs 1
Name:                ansible-2.9
Summary:             SSH-based configuration management, deployment, and task execution system
Version:             2.9.24
Release:             2
License:             GPLv3+
Source0:             https://releases.ansible.com/ansible/ansible-%{version}.tar.gz
Source1:             ansible.attr
Source2:             ansible-generator
Source3:             macros.ansible
Url:                 http://ansible.com
BuildArch:           noarch
Patch1:              ansible-2.9.22-rocky.patch
Patch2:              ansible-2.9.6-disable-test_build_requirement_from_path_no_version.patch
Patch3:              fix-python-3.9-compatibility.patch
Patch4:              Disable-strict-markers-with-pytest-3.6.patch
Patch5:              Skip-some-test-cases-that-fail-because-the-pytest-too-old.patch
Patch6:              ansible-2.9.23-sphinx4.patch
Patch7:              ansible-2.9.27-pyyaml-6-compat.patch
Provides:            ansible-2.9-python3 = %{version}-%{release}
Obsoletes:           ansible-2.9-python3 < %{version}-%{release}
Conflicts:           ansible-base > 2.10.0
Conflicts:           ansible-core > 2.11.0
BuildRequires:       python3-packaging python3-pexpect python3-paramiko python3-pywinrm
BuildRequires:       python3-crypto python3-pbkdf2 python3-httmock python3-python-gitlab
BuildRequires:       python3-boto3 python3-botocore python3-coverage python3-passlib git-core
BuildRequires:       openssl
%if 0%{?with_docs}
BuildRequires:       python3-sphinx python3-sphinx-theme-alabaster python3-sphinx-notfound-page
BuildRequires:       asciidoc python3-straight-plugin
%endif
BuildRequires:       python3-devel python3-setuptools python3-six python3-pytest
BuildRequires:       python3-pytest-xdist python3-pytest-mock python3-requests python3-mock
BuildRequires:       python3-jinja2 python3-pyyaml python3-cryptography python3-pyvmomi make
Recommends:          python3-paramiko
Recommends:          python3-winrm
Requires:            python3-setuptools python3-six python3-jinja2 python3-pyyaml sshpass
Requires:            python3-jmespath
%description
Ansible is a radically simple model-driven configuration management,
multi-node deployment, and remote task execution system. Ansible works
over SSH and does not require any software or daemons to be installed
on remote nodes. Extension modules can be written in any language and
are transferred to managed machines automatically.

%package -n ansible-2.9-doc
Summary:             Documentation for Ansible
Conflicts:           ansible-doc
%description -n ansible-2.9-doc
Ansible is a radically simple model-driven configuration management,
multi-node deployment, and remote task execution system. Ansible works
over SSH and does not require any software or daemons to be installed
on remote nodes. Extension modules can be written in any language and
are transferred to managed machines automatically.
This package installs extensive documentation for ansible

%package -n ansible-2.9-test
Summary:             Tool for testing ansible plugin and module code
Requires:            %{name} = %{version}-%{release}
Conflicts:           ansible-test

%description -n ansible-2.9-test
Ansible is a radically simple model-driven configuration management,
multi-node deployment, and remote task execution system. Ansible works
over SSH and does not require any software or daemons to be installed
on remote nodes. Extension modules can be written in any language and
are transferred to managed machines automatically.
This package installs the ansible-test command for testing modules and plugins
developed for ansible.

%prep
%autosetup -p1 -n ansible-%{version}
cp -a %{S:1} %{S:2} %{S:3} .

%build
sed -i -e 's|/usr/bin/env python|/usr/bin/python3|' test/lib/ansible_test/_data/*.py test/lib/ansible_test/_data/*/*.py test/lib/ansible_test/_data/*/*/*.py docs/bin/find-plugin-refs.py
sed -i -s 's|/usr/bin/env pwsh||' test/lib/ansible_test/_data/sanity/validate-modules/validate_modules/ps_argspec.ps1
sed -i -s 's|/usr/bin/env pwsh||' test/lib/ansible_test/_data/sanity/pslint/pslint.ps1
sed -i -s 's|/usr/bin/env pwsh||' test/lib/ansible_test/_data/requirements/sanity.ps1
%global py3_shbang_opts %(echo %{py3_shbang_opts} | sed 's/-s//')
%py3_build
%if 0%{?with_docs}
  make PYTHON=/usr/bin/python3 SPHINXBUILD=sphinx-build-3 webdocs
%else
  make PYTHON=/usr/bin/python3 -Cdocs/docsite config cli keywords modules plugins testing
%endif

%install
%py3_install
DATADIR_LOCATIONS='%{_datadir}/ansible/collections
%{_datadir}/ansible/collections/ansible_collections
%{_datadir}/ansible/plugins/doc_fragments
%{_datadir}/ansible/plugins/action
%{_datadir}/ansible/plugins/become
%{_datadir}/ansible/plugins/cache
%{_datadir}/ansible/plugins/callback
%{_datadir}/ansible/plugins/cliconf
%{_datadir}/ansible/plugins/connection
%{_datadir}/ansible/plugins/filter
%{_datadir}/ansible/plugins/httpapi
%{_datadir}/ansible/plugins/inventory
%{_datadir}/ansible/plugins/lookup
%{_datadir}/ansible/plugins/modules
%{_datadir}/ansible/plugins/module_utils
%{_datadir}/ansible/plugins/netconf
%{_datadir}/ansible/roles
%{_datadir}/ansible/plugins/strategy
%{_datadir}/ansible/plugins/terminal
%{_datadir}/ansible/plugins/test
%{_datadir}/ansible/plugins/vars'
UPSTREAM_DATADIR_LOCATIONS=$(grep -ri default lib/ansible/config/base.yml| tr ':' '\n' | grep '/usr/share/ansible')
if [ "$SYSTEM_LOCATIONS" != "$UPSTREAM_SYSTEM_LOCATIONS" ] ; then
	echo "The upstream Ansible datadir locations have changed.  Spec file needs to be updated"
	exit 1
fi
mkdir -p $RPM_BUILD_ROOT%{_datadir}/ansible/plugins/
for location in $DATADIR_LOCATIONS ; do
	mkdir $RPM_BUILD_ROOT"$location"
done
mkdir -p $RPM_BUILD_ROOT/etc/ansible/
mkdir -p $RPM_BUILD_ROOT/etc/ansible/roles/
cp examples/hosts $RPM_BUILD_ROOT/etc/ansible/
cp examples/ansible.cfg $RPM_BUILD_ROOT/etc/ansible/
mkdir -p $RPM_BUILD_ROOT/%{_mandir}/man1
cp -v docs/man/man1/*.1 $RPM_BUILD_ROOT/%{_mandir}/man1/
cp -pr docs/docsite/rst .
%if 0%{?with_docs}
  cp -pr docs/docsite/_build/html %{_builddir}/ansible-%{version}/html
%endif
install -Dpm0644 -t %{buildroot}%{_fileattrsdir} ansible.attr
install -Dpm0644 -t %{buildroot}%{_rpmmacrodir} macros.ansible
install -Dpm0755 -t %{buildroot}%{_rpmconfigdir} ansible-generator

%check
ln -s /usr/bin/pytest-3 bin/pytest
pathfix.py -i %{__python3} -p test/lib/ansible_test/_data/cli/ansible_test_cli_stub.py
rm -f test/units/modules/cloud/cloudstack/test_cs_traffic_type.py
rm -f test/units/module_utils/facts/hardware/test_sunos_get_uptime_facts.py
rm -f test/units/modules/source_control/test_gitlab_runner.py
rm -f test/units/plugins/lookup/test_aws_secret.py
rm -f test/units/plugins/lookup/test_aws_ssm.py
make PYTHON=/usr/bin/python3 tests-py3

%files
%license COPYING
%doc README.rst PKG-INFO changelogs/CHANGELOG-v2.9.rst
%doc %{_mandir}/man1/ansible*
%config(noreplace) %{_sysconfdir}/ansible/
%{_bindir}/ansible*
%{_datadir}/ansible/
%{python3_sitelib}/ansible
%{python3_sitelib}/ansible_test
%{python3_sitelib}/*egg-info
%{_fileattrsdir}/ansible.attr
%{_rpmmacrodir}/macros.ansible
%{_rpmconfigdir}/ansible-generator
%exclude %{_bindir}/ansible-test
%exclude %{python3_sitelib}/ansible_test

%files -n ansible-2.9-doc
%doc rst
%if 0%{?with_docs}
%doc html
%endif

%files -n ansible-2.9-test
%{_bindir}/ansible-test
%{python3_sitelib}/ansible_test

%changelog
* Mon May 9 2022 yaoxin <yaoxin30@h-partners.com> - 2.9.24-2
- Remove the python-nose compilation dependency and resolve the compilation error.

* Tue Sep 14 2021 huanghaitao <huanghaitao8@huawei.com> - 2.9.24-1
- package init
