search
HomeSystem TutorialLINUXSummary of ansible usage: ansible installation

Summary of ansible usage: ansible installation

Aug 24, 2024 am 07:31 AM
linuxlinux tutorialRed Hatlinux systemlinux commandlinux certificationred hat linuxlinux video

Summary of ansible usage: ansible installation

1. Introduction

Ansible is a configuration management and application deployment tool. Its functions are similar to the current industry configuration management tools Chef, Puppet, and Saltstack. Ansible is developed using the Python language. The Ansible platform was created by Michael DeHaan, the author of the well-known software Cobbler and Func. The first version of Ansible was released in February 2012. Ansible manages machines through the SSH protocol by default, so Ansible does not need to install a client program on the server. You only need to install Ansible on one server. After Ansible is installed, you can manage and control other servers. There is no need to configure a database for it, and Ansible does not start or keep running as daemons. Ansible can achieve the following goals:

  • Automated deployment of applications
  • Automated management configuration
  • Automated continuous delivery
  • Automated (AWS) cloud service management.

According to the official information provided by Ansible, users currently using Ansible include: evernote, rackspace, NASA, Atlassian, twitter, etc.

Note: The above introduction comes from the introduction of ibm developerworks China.

2. Ansible installation
1. Yum source installation

Take centos as an example. There is no ansible in the source by default, but there is ansible in the fedora epel source. After configuring the epel source, you can install it directly through yum. Here is centos6.8 as an example:

# yum install http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
# yum install ansible
2. apt-get installation

In ubuntu and its derivatives, you can install apt-get by adding ppa source, 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. Source code installation
Source code installation requires python2.6 or above, which depends on the modules paramiko, PyYAML, Jinja2, httplib2, simplejson, and pycrypto modules. The above modules can be installed through pip or easy_install. However, since this section mentions source code installation, it is mainly aimed at those that cannot If you are connected to the Internet, you can search for the above package through the pypi site, download it and install it through python setup.py install.

Finally, download the ansible source code package from github or pypi and install it through python setup.py install. Since the installation process is relatively simple, we will skip it here and mainly introduce the problems you may encounter after installation.

a. When installing PyYAML, the error is reported as follows:

# python setup.py install
libyaml is not found or a compiler error: forcing --without-libyaml
(if libyaml is installed correctly, you may need to
specify the option --include-dirs or uncomment and
modify the parameter include_dirs in setup.cfg)
running install_lib
running install_egg_info
Removing /usr/lib64/python2.6/site-packages/PyYAML-3.11-py2.6.egg-info
Writing /usr/lib64/python2.6/site-packages/PyYAML-3.11-py2.6.egg-info

In centos6.8 system, it can be solved through yum -y install libyaml package, or provide the package from the ISO file and install it through rpm -ivh.

b. After installing ansible, the error is as follows:

[root@361way.com ansible-1.9.1]# ansible -h
Traceback (most recent call last):
File "/usr/local/src/ansible-devel/bin/ansible", line 36, in 
from ansible.runner import Runner
File "/usr/local/src/ansible-devel/lib/ansible/runner/__init__.py", line 62, in 
from Crypto.Random import atfork
File "/usr/lib64/python2.6/site-packages/Crypto/Random/__init__.py", line 29, in 
from Crypto.Random import _UserFriendlyRNG
File "/usr/lib64/python2.6/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, in 
from Crypto.Random.Fortuna import FortunaAccumulator
File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in 
import FortunaGenerator
File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 34, in 
from Crypto.Util.number import ceil_shift, exact_log2, exact_div
File "/usr/lib64/python2.6/site-packages/Crypto/Util/number.py", line 56, in 
if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:
AttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'

When importing the paramiko package, the error is reported as follows:

>>> import paramiko
Traceback (most recent call last):
File "", line 1, in 
File "/usr/lib/python2.6/site-packages/paramiko/__init__.py", line 69, in 
from transport import randpool, SecurityOptions, Transport
File "/usr/lib/python2.6/site-packages/paramiko/transport.py", line 32, in 
from paramiko import util
File "/usr/lib/python2.6/site-packages/paramiko/util.py", line 32, in 
from paramiko.common import *
File "/usr/lib/python2.6/site-packages/paramiko/common.py", line 98, in 
from rng import StrongLockingRandomPool
File "/usr/lib/python2.6/site-packages/paramiko/rng.py", line 22, in 
from Crypto.Util.randpool import RandomPool as _RandomPool
File "/usr/lib64/python2.6/site-packages/Crypto/Util/randpool.py", line 30, in 
import Crypto.Random
File "/usr/lib64/python2.6/site-packages/Crypto/Random/__init__.py", line 29, in 
from Crypto.Random import _UserFriendlyRNG
File "/usr/lib64/python2.6/site-packages/Crypto/Random/_UserFriendlyRNG.py", line 38, in 
from Crypto.Random.Fortuna import FortunaAccumulator
File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaAccumulator.py", line 39, in 
import FortunaGenerator
File "/usr/lib64/python2.6/site-packages/Crypto/Random/Fortuna/FortunaGenerator.py", line 34, in 
from Crypto.Util.number import ceil_shift, exact_log2, exact_div
File "/usr/lib64/python2.6/site-packages/Crypto/Util/number.py", line 56, in 
if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:
AttributeError: 'module' object has no attribute 'HAVE_DECL_MPZ_POWM_SEC'

After searching online, it was confirmed that the GMP version that the pycrypto package depends on when installing is incorrect. The details can be verified through the following steps:

[root@361way.com pycrypto-2.6.1]# python setup.py build
running build
running build_py
running build_ext
running build_configure
warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.

Solution:

Open the /usr/lib64/python2.6/site-packages/Crypto/Util/number.py file, you can see the comment on line 56, which requires libgmp to be v5 or above. The current version of the system is 4.1.4. If you temporarily comment out the following two lines, Ansible will execute normally.

if _fastmath is not None and not _fastmath.HAVE_DECL_MPZ_POWM_SEC:
_warn("Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack 
vulnerability.", PowmInsecureWarning)

However, this method is only a temporary solution. A better way is to upgrade libgmp to a version that meets the requirements.

c. An error occurs during execution

[root@361way.com src]# ansible test -m raw -a 'uptime'
10.212.52.14 | FAILED => to use the 'ssh' connection type with passwords, you must install the sshpass program
10.212.52.16 | FAILED => to use the 'ssh' connection type with passwords, you must install the sshpass program

Install the sshpass program. It is not available in the default source. I chose to download and install it directly from the sohu source.

3. Ansible configuration and verification

There is an examles package in the source code downloaded from pypi. You can use this example file as the default configuration, as follows:

[root@361way.com ansible-1.9.1]# mkdir -p /etc/ansible
[root@361way.com ansible-1.9.1]# cp -rp examples/* /etc/ansible/
[root@361way.com ansible-1.9.1]# cd /etc/ansible/

After using the default sample configuration file, edit the /etc/ansible/hosts file and verify whether ansible is available by:

[root@361way.com ~]# cat /etc/ansible/hosts
[test]
10.212.52.252 ansible_ssh_user=root ansible_ssh_pass=361way.com
10.212.52.14 ansible_ssh_user=root ansible_ssh_pass=abc123
10.212.52.16 ansible_ssh_user=root ansible_ssh_pass=91it.org

In the above configuration, I configured a test group. There are three hosts in this group. All three hosts use root authentication. The passwords of the three hosts are 361way.com, abc123, and 91it.org.

Note: The following user and password items are optional. When key authentication is configured, you can operate directly without using a password. If a key is not used, you can also use the -k parameter in ansible to ask for a manual password before the operation.

[root@361way.com ~]# ansible test -a 'uptime'
10.212.52.252 | success | rc=0 >>
18:01pm up 21 days 3:24, 3 users, load average: 0.39, 0.38, 0.35
10.212.52.16 | success | rc=0 >>
18:09pm up 329 days 1:01, 2 users, load average: 0.08, 0.03, 0.05
10.212.52.14 | success | rc=0 >>
18:08pm up 329 days 0:23, 2 users, load average: 0.06, 0.06, 0.05

After executing the above instructions, the results will be output, proving that the installation is successful.

The above is the detailed content of Summary of ansible usage: ansible installation. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the architectural differences between Linux and Windows.Explain the architectural differences between Linux and Windows.May 06, 2025 am 12:01 AM

The main differences in architecture between Linux and Windows include: 1) Design philosophy and kernel structure: Linux uses a modular kernel, Windows uses a single kernel; 2) File system: Linux supports multiple file systems, Windows mainly uses NTFS; 3) Security: Linux is known for its permission management and open source features. Windows has a unique security mechanism but lags in repair; 4) Usage experience: Linux command line operation is more efficient, and Windows graphical interface is more intuitive.

What are some common security threats targeting Linux versus Windows?What are some common security threats targeting Linux versus Windows?May 05, 2025 am 12:03 AM

Linux and Windows systems face different security threats. Common Linux threats include Rootkit, DDoS attacks, exploits, and permission escalation; common Windows threats include malware, ransomware, phishing attacks, and zero-day attacks.

How does process management differ between Linux and Windows?How does process management differ between Linux and Windows?May 04, 2025 am 12:04 AM

The main difference between Linux and Windows in process management lies in the implementation and concept of tools and APIs. Linux is known for its flexibility and power, relying on kernel and command line tools; while Windows is known for its user-friendliness and integration, mainly managing processes through graphical interfaces and system services.

What are the typical use cases for Linux versus Windows?What are the typical use cases for Linux versus Windows?May 03, 2025 am 12:01 AM

Linuxisidealforcustomization,development,andservermanagement,whileWindowsexcelsineaseofuse,softwarecompatibility,andgaming.Linuxoffershighconfigurabilityfordevelopersandserversetups,whereasWindowsprovidesauser-friendlyinterfaceandbroadsoftwaresupport

What are the differences in user account management between Linux and Windows?What are the differences in user account management between Linux and Windows?May 02, 2025 am 12:02 AM

The main difference between Linux and Windows in user account management is the permission model and management tools. Linux uses Unix-based permissions models and command-line tools (such as useradd, usermod, userdel), while Windows uses its own security model and graphical user interface (GUI) management tools.

How does the command line environment of Linux make it more/less secure than Windows?How does the command line environment of Linux make it more/less secure than Windows?May 01, 2025 am 12:03 AM

Linux'scommandlinecanbemoresecurethanWindowsifmanagedcorrectly,butrequiresmoreuserknowledge.1)Linux'sopen-sourcenatureallowsforquicksecurityupdates.2)Misconfigurationcanleadtovulnerabilities.Windows'commandlineismorecontrolledbutlesscustomizable,with

How to Make a USB Drive Mount Automatically in LinuxHow to Make a USB Drive Mount Automatically in LinuxApr 30, 2025 am 10:04 AM

This guide explains how to automatically mount a USB drive on boot in Linux, saving you time and effort. Step 1: Identify Your USB Drive Use the lsblk command to list all block devices. Your USB drive will likely be labeled /dev/sdb1, /dev/sdc1, etc

Best Cross-Platform Apps for Linux, Windows, and Mac in 2025Best Cross-Platform Apps for Linux, Windows, and Mac in 2025Apr 30, 2025 am 09:57 AM

Cross-platform applications have revolutionized software development, enabling seamless functionality across operating systems like Linux, Windows, and macOS. This eliminates the need to switch apps based on your device, offering consistent experien

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.