%global with_docs 0
%global with_python3 1
Name:                ansible
Summary:             SSH-based configuration management, deployment, and task execution system
Version:             2.5.5
Release:             8
License:             Python-2.0 and MIT and GPL+
Url:                 http://ansible.com
Source0:             https://releases.ansible.com/ansible/%{name}-%{version}.tar.gz
Patch0:              0001-Changes-to-support-building-docs-with-old-jinja2.patch
Patch100:            ansible-newer-jinja.patch
Patch101:            CVE-2019-14904.patch
Patch102:            CVE-2020-10684.patch
Patch103:            CVE-2020-10729.patch
Patch106:            CVE-2020-1737.patch
Patch108:            CVE-2020-1739.patch
Patch109:            CVE-2020-1740.patch
Patch110:            CVE-2020-1753.patch
Patch111:            CVE-2021-20191.patch
Patch112:            CVE-2019-10156-1.patch
Patch113:            CVE-2019-10156-2.patch
Patch114:            CVE-2020-1735.patch
Patch115:            CVE-2019-3828.patch
Patch116:            ansible-2.5.5-openEuler-hostname.patch
Patch117:            CVE-2024-0690.patch
Patch118:            CVE-2022-3697.patch
Patch119:            CVE-2023-5115.patch
BuildArch:           noarch
Provides:            ansible-fireball = %{version}-%{release}
Obsoletes:           ansible-fireball < 1.2.4
BuildRequires:       python3-jinja2 python3-devel python3-packaging python3-pyyaml
Requires:            python3-PyYAML python3-crypto python3-paramiko python3-keyczar
Requires:            python3-setuptools python3-six sshpass python3-httplib2
Requires:            python3-jmespath python3-jinja2 
Recommends:          %{name}-help = %{version}-%{release}
%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.
%if 0%{?with_python3}
Provides:            ansible-python3 = %{version}-%{release}
Obsoletes:           ansible-python3 < %{version}-%{release}
BuildRequires:       python3-devel python3-setuptools
BuildRequires:       python3-PyYAML python3-paramiko python3-crypto python3-packaging
BuildRequires:       python3-pexpect python3-pywinrm
BuildRequires:       git-core
%if %with_docs
BuildRequires:       python3-sphinx python3-sphinx-theme-alabaster asciidoc
%endif
BuildRequires:       python3-six python3-nose python3-pytest python3-pytest-xdist
BuildRequires:       python3-pytest-mock python3-requests python3-coverage python3-mock
BuildRequires:       python3-boto3 python3-botocore python3-passlib python3-jinja2
Requires:            python3-PyYAML python3-paramiko python3-crypto python3-setuptools python3-six
Requires:            python3-jinja2 sshpass 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.
This package installs versions of ansible that execute on Python3.
%endif

%package -n ansible-help
Summary:             Documentation for Ansible
Provides:            %{name}-doc = %{name}-%{release}
Obsoletes:           %{name}-doc < %{name}-%{release}
%description -n ansible-help
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

%prep
%setup -q
%patch0 -p1
%patch100 -p1
%patch101 -p1
%patch102 -p1
%patch103 -p1
%patch106 -p1
%patch108 -p1
%patch109 -p1
%patch110 -p1
%patch111 -p1
%patch112 -p1
%patch113 -p1
%patch114 -p1
%patch115 -p1
%patch116 -p1
%patch117 -p1
%patch118 -p1
%patch119 -p1
%if 0%{?with_python3}
rm -rf %{py3dir}
cp -a . %{py3dir}
%endif

%build
%if 0%{?with_python3}
pushd %{py3dir}
%py3_build
%if %with_docs
  pathfix.py -i %{__python3} -p docs/bin test/runner
  make PYTHON=/usr/bin/python3 SPHINXBUILD=sphinx-build-3 webdocs
%endif
popd
%endif 

%install
%if 0%{?with_python3}
pushd %{py3dir}
%{__python3} setup.py install --root=$RPM_BUILD_ROOT
popd
for i in $RPM_BUILD_ROOT/%{_bindir}/ansible* ; do
    if [ $(basename $i) = "ansible-connection" -o $(basename $i) = "ansible" ] ; then
            ln -s $(basename $i) $i-%{python3_version}
        ln -s %{_bindir}/$(basename $i)-%{python3_version} $i-3
    fi
done
%endif 
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 %with_docs
  pushd %{py3dir}
  cp -pr docs/docsite/_build/html %{_builddir}/%{name}-%{version}/html
  popd
%endif

%check

%files
%defattr(-,root,root)
%{_bindir}/ansible*
%config(noreplace) %{_sysconfdir}/ansible/
%doc README.rst PKG-INFO COPYING changelogs/CHANGELOG-v2.5.rst
%doc %{_mandir}/man1/ansible*
%if 0%{?with_python3}
%{python3_sitelib}/ansible*
%endif

%files -n ansible-help
%doc rst
%if %with_docs
%doc html
%endif

%changelog
* Sat Feb 08 2025 wangkai <13474090681@163.com> - 2.5.5-8
- Fix CVE-2022-3697 CVE-2023-5115

* Mon Feb 05 2024 wangkai <13474090681@163.com> - 2.5.5-7
- Fix CVE-2024-0690

* Fri Oct 13 2023 Ge Wang <wang__ge@126.com> - 2.5.5-6
- Change BuildRequire python3-winrm to python3-pywinrm

* Mon Feb 28 2022 wangkai <wangkai385@huawei.com> - 2.5.5-5
- Fix CVE-2019-3828 and hostname module support openEuler
- and add defination of is_subpath and remove module_response_deepcopy

* Thu Oct 28 2021 liwu <liwu13@huawei.com> - 2.5.5-4
- The upstream community rolls back the patch

* Wed Oct 13 2021 yaoxin <yaoxin30@huawei.com> - 2.5.5-3
- Fix CVE-2019-10156

* Fri Sep 17 2021 yaoxin <yaoxin30@huawei.com> - 2.5.5-2
- Fix CVE-2019-14904 CVE-2020-10684 CVE-2020-10729 CVE-2020-1735-to-CVE-2020-1740 CVE-2020-1753 CVE-2021-20191

* Tue Jan 12 2021 yanan li <liyanan32@huawei.com> - 2.5.5-1
- Package init
