In today’s rapidly developing information technology era, automated operations are no longer a luxury but a necessity for improving efficiency and ensuring stability. What solution for automated operations? Ansible, as a powerful automation tool, stands out among many operational tools with its simplicity, ease of use, and efficiency. This article will guide you on how to deploy Ansible in a Linux system and outline its key advantages and common problem-solving methods.

Advantages of Ansible

Ansible is an automation tool developed based on Python, integrating the advantages of tools like puppet, chef, func, and fabric, offering functions such as batch system configuration, program deployment, and task execution. The advantage of Ansible lies in its simple architecture, as it does not require the installation of extra agents on the client side of Linux systems, and remote management can be performed simply through SSH. Additionally, Ansible uses the YAML language to write automation scripts, which are easy to read and write, reducing the difficulty of operation and maintenance work.

Deploying Ansible in Linux

1. Installing via YUM repository (CentOS example)

By default, CentOS’s official repository may not contain Ansible, but we can install it by adding the EPEL (Extra Packages for Enterprise Linux) repository. For example, to deploy Ansible on CentOS 6.8, you need to execute the following commands:

sudo yum install
sudo yum install ansible

2. Installing via APT-GET (for Debian-based systems)

On Ubuntu and its derivatives, Ansible can be installed by adding the PPA (Personal Package Archive) repository. The steps are as follows:

sudo apt-get install software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install ansible

3. Installing from source

If your system can’t connect to the external network, or you need a specific version of Ansible, you can choose to install from the source. First, ensure Python version is 2.6 or above and install the necessary dependencies:

sudo pip install paramiko PyYAML Jinja2 httplib2 simplejson pycrypto

Then download the source code of Ansible from GitHub or PyPI and install:

sudo python install

Common Problems and Solutions

Problem 1: Issues installing PyYAML

When installing PyYAML, you may encounter the following error message:

libyaml is not found or a compiler error: forcing --without-libyaml

This is usually due to the absence of the libyaml library. In CentOS systems, you can install libyaml with the following command:

sudo yum -y install libyaml

Alternatively, if you have an ISO file, you can extract and install the relevant packages from it.

Problem 2: Ansible execution errors

After installation, trying to run Ansible may result in the following error:

AttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'

This is usually caused by a mismatch between the pycrypto package and the system’s GMP library versions. You can try updating the GMP library or temporarily comment out the problematic part in