Install Ansible in CentOS 7
Ansible is used to configure Windows and Linux computers with scripts. If you perform all configuration through Ansible scripts, you can set up a new computer with the same configuration as before, without repeating the work.
Prerequisites
"Download Computer": An Internet-connected computer to download the Ansible software and Python packages.
"Control Machine": A computer with CentOS 7 or other Red Hat 7 compatible Linux, and these "yum" packages:
python
python-setuptools
python-devel
openssl-devel
git
sshd
"Managed Node": One or more computers to configure.
SSH access or
PowerShell access
Install CentOS packages
Install the libffi package:
sudo yum install libffi
Download
We'll use pip to download ansible and all python prerequisites.
Download pip in a Linux environment:
curl -O https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
Download the Python packages and Ansible:
pip download virtualenv
pip download pip
pip download wheel
pip download ansible
Download the latest Ansible package, which contains example configuration files:
curl -O http://releases.ansible.com/ansible/ansible-latest.tar.gz
Transfer files to the control machine:
*.whl
*.tar.gz
Installing
Connect to the control machine by SSH.
Install pip to the system, using the local packages:
sudo python get-pip.py --no-index --find-links=.
Install virtualenv to the system, using pip:
sudo pip install --no-index --find-links=. virtualenv
Create a new virtualenv for Ansible:
virtualenv --system-site-packages ansible
Use the new virtualenv:
source ansible/bin/activate
Install Ansible using pip
pip install --no-index --find-links=. ansible
If you receive errors, check that all prerequisite packages have been installed to the control machine.
Now the Ansible binary is installed in the ansible/bin/ directory.
Configuration
Extract the latest Ansible package:
tar xvfz ansible-latest.tar.gz
Copy the example hosts and ansible.cfg files:
cp -p ansible-*/examples/* ansible/
Edit the hosts file to include the managed nodes
cd ansible
vi hosts
Add machine names or IP addresses under groups, and save the file. Example below:
# Unorganized machines
node1
# Minecraft servers
[minecraft]
node1
# IRC clients
[irc]
node1
Edit the Ansible configuration file
vi ansible.cfg
Add some entries under [defaults], and save the file
inventory = ./hosts
log_path = ./ansible.log
References
I used the following links to learn how to do this:
http://blog.scottlowe.org/2016/04/30/installing-ansible-in-virtualenv/
http://joeyoung.io/ansible-installation-on-centos-7-workarounds/