%define name ansible
%define srcname ansible
%define version 2.2.2.0
%define release 1

%define is_python %(test -e /usr/bin/python && echo 1 || echo 0)
%if %{is_python}
%define python_sitelib %(python -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")
%endif

%define _libdir64 %{_prefix}/lib64

%define is_python_64 %(test -e /usr/bin/python_64 && echo 1 || echo 0)
%if %{is_python_64}
%define python_sitelib64 %(python_64 -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")
%endif

Summary: SSH-based configuration management, deployment, and task execution system
Name: %{name}
Version: %{version}
Release: %{release}
Source0: %{srcname}-%{version}.tar.gz
License: BSD
Group: Development/Libraries

#Patch100: ansible-newer-jinja.patch
Source1: ansible-unittests-%{version}.tar.xz
Source100: get-unittests.sh

BuildRequires: python, python-devel
BuildRequires: python-PyYAML
BuildRequires: python-paramiko
BuildRequires: python-keyczar
BuildRequires: python-httplib2
BuildRequires: python-setuptools
BuildRequires: python-six
BuildRequires: python-nose
BuildRequires: python-coverage
BuildRequires: python-mock
BuildRequires: python-boto3
BuildRequires: python-botocore
BuildRequires: python-passlib
BuildRequires: python-jinja2
BuildRequires: python-pycrypto

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
Prefix: %{_prefix}
Vendor: Ned Batchelder and others <ned@nedbatchelder.com>
Url: http://nedbatchelder.com/code/coverage
Requires: python
Requires: python-PyYAML
Requires: python-paramiko
Requires: python-jinja2
Requires: python-keyczar
Requires: python-httplib2
Requires: python-setuptools
Requires: python-six
Requires: python-pycrypto
Requires: sshpass


Provides: ansible-fireball = %{version}-%{release}
Obsoletes: ansible-fireball < 1.2.4


%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.
%prep
%setup -n %{srcname}-%{version}
#%patch100 -p1
tar -xJvf %{SOURCE1}

mkdir ../32bit
mv * ../32bit
mv ../32bit .
mkdir 64bit
cp -r 32bit/* 64bit/

%build
export OBJECT_MODE=64
cd 64bit
python_64 setup.py build

export OBJECT_MODE=32
cd ../32bit
python setup.py build

%install
[ -d "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT

cd 64bit
python_64 setup.py install --skip-build --root ${RPM_BUILD_ROOT}


cd ../32bit
python setup.py install --skip-build --root ${RPM_BUILD_ROOT}
mkdir -p $RPM_BUILD_ROOT%{_prefix}/etc/ansible/
mkdir -p $RPM_BUILD_ROOT%{_prefix}/etc/ansible/roles/
cp examples/hosts $RPM_BUILD_ROOT%{_prefix}/etc/ansible/
cp examples/ansible.cfg $RPM_BUILD_ROOT%{_prefix}/etc/ansible/
mkdir -p $RPM_BUILD_ROOT/%{_mandir}/man1
cp  docs/man/man1/*.1 $RPM_BUILD_ROOT/%{_mandir}/man1/
mkdir -p $RPM_BUILD_ROOT/%{_datadir}/ansible
mkdir -p $RPM_BUILD_ROOT/%{_datadir}/ansible_plugins/{action,callback,connection,lookup,vars,filter}_plugins
#make tests
cd ${RPM_BUILD_ROOT}
mkdir -p usr/bin
cd usr/bin
ln -sf ../..%{_bindir}/* .


%clean
[ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf ${RPM_BUILD_ROOT}

%files
%defattr(-,root,system,-)
%{python_sitelib}/ansible*
#%{python_sitelib64}/ansible*
%{_bindir}/ansible*
/usr/bin/ansible*
%config(noreplace) %{_sysconfdir}/ansible/
%doc 32bit/README.md 32bit/PKG-INFO 32bit/COPYING 32bit/CHANGELOG.md
%doc %{_mandir}/man1/ansible*

%changelog
* Thu May 11 2017 Ravi Hirekurabar <rhirekur@in.ibm.com> - 2.2.2.0-1
- first version for AIX V6.1 and higherj
