Home System Tutorial LINUX Summary of ansible usage: ansible installation

Summary of ansible usage: ansible installation

Aug 24, 2024 am 07:31 AM
linux linux tutorial Red Hat linux system linux command linux certification red hat linux linux 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
Copy after login
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
Copy after login

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
Copy after login

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'
Copy after login

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'
Copy after login

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.
Copy after login

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)
Copy after login

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
Copy after login

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/
Copy after login

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
Copy after login

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
Copy after login

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 of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1254
29
C# Tutorial
1228
24
Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

vscode terminal usage tutorial vscode terminal usage tutorial Apr 15, 2025 pm 10:09 PM

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

vscode Previous Next Shortcut Key vscode Previous Next Shortcut Key Apr 15, 2025 pm 10:51 PM

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

laravel installation code laravel installation code Apr 18, 2025 pm 12:30 PM

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

See all articles