Home> System Tutorial> LINUX> body text

Summary of ansible usage: ansible installation

WBOY
Release: 2024-08-24 07:31:14
Original
617 people have browsed it

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!

source:linuxprobe.com
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!