Erlo

在CentOS7.6上安装自动化运维工具Ansible以及playbook案例实操

2019-04-08 16:00:15 发布   1079 浏览  
页面报错/反馈
收藏 点赞

前言

Ansible是一款优秀的自动化IT运维工具,具有远程安装、远程部署应用、远程管理能力,支持Windows、Linux、Unix、macOS和大型机等多种操作系统。

下面就以CentOS 7.6为主机操作系统,演示安装Ansible工具的过程,将一个本地应用例子安装到远程主机,并在远程主机上运行应用。

 一、环境准备

完成这个例子,最少需要两台主机,一台安装Ansible运维工具本身,用作管理主机,一台用作远程目标主机。

两台主机都预先安装了CentOS 7.6操作系统。

# Ansible管理主机

192.168.6.190  root@k3s-vip

# 远程目标主机

 192.168.6.193  root@k3s-node3 

二、安装Ansible运维工具

使用SSH登录到拟安装Ansible的主机。

  • 查看系统环境:
[root@k3s-vip ~]# uname -a
Linux k3s-vip 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • 运行安装命令

Ansible的安装过程很简单,只需要一条yum命令。

使用CentOS自带工具yum自动下载、安装Ansible。Ansible依赖于Python语言,安装Ansible时会自动下载、安装Python语言包。

安装过程中会提示是否安装依赖软件包,全部选y。

[root@k3s-vip ~]# yum install ansible
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
 * base: centos.ustc.edu.cn
 * extras: mirrors.cqu.edu.cn
 * updates: mirrors.cqu.edu.cn
base                                                                                                                                                                                   | 3.6 kB  00:00:00     
extras                                                                                                                                                                                 | 3.4 kB  00:00:00     
updates                                                                                                                                                                                | 3.4 kB  00:00:00     
(1/2): extras/7/x86_64/primary_db                                                                                                                                                      | 187 kB  00:00:01     
(2/2): updates/7/x86_64/primary_db                                                                                                                                                     | 3.4 MB  00:00:15     
Resolving Dependencies
--> Running transaction check
---> Package ansible.noarch 0:2.4.2.0-2.el7 will be installed
--> Processing Dependency: sshpass for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python2-jmespath for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python-passlib for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python-paramiko for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python-jinja2 for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python-httplib2 for package: ansible-2.4.2.0-2.el7.noarch
--> Processing Dependency: python-cryptography for package: ansible-2.4.2.0-2.el7.noarch
--> Running transaction check
---> Package python-httplib2.noarch 0:0.9.2-1.el7 will be installed
---> Package python-jinja2.noarch 0:2.7.2-2.el7 will be installed
--> Processing Dependency: python-babel >= 0.8 for package: python-jinja2-2.7.2-2.el7.noarch
--> Processing Dependency: python-markupsafe for package: python-jinja2-2.7.2-2.el7.noarch
---> Package python-paramiko.noarch 0:2.1.1-9.el7 will be installed
--> Processing Dependency: python2-pyasn1 for package: python-paramiko-2.1.1-9.el7.noarch
---> Package python-passlib.noarch 0:1.6.5-2.el7 will be installed
---> Package python2-cryptography.x86_64 0:1.7.2-2.el7 will be installed
--> Processing Dependency: python-idna >= 2.0 for package: python2-cryptography-1.7.2-2.el7.x86_64
--> Processing Dependency: python-cffi >= 1.4.1 for package: python2-cryptography-1.7.2-2.el7.x86_64
--> Processing Dependency: python-enum34 for package: python2-cryptography-1.7.2-2.el7.x86_64
---> Package python2-jmespath.noarch 0:0.9.0-3.el7 will be installed
---> Package sshpass.x86_64 0:1.06-2.el7 will be installed
--> Running transaction check
---> Package python-babel.noarch 0:0.9.6-8.el7 will be installed
---> Package python-cffi.x86_64 0:1.6.0-5.el7 will be installed
--> Processing Dependency: python-pycparser for package: python-cffi-1.6.0-5.el7.x86_64
---> Package python-enum34.noarch 0:1.0.4-1.el7 will be installed
---> Package python-idna.noarch 0:2.4-1.el7 will be installed
---> Package python-markupsafe.x86_64 0:0.11-10.el7 will be installed
---> Package python2-pyasn1.noarch 0:0.1.9-7.el7 will be installed
--> Running transaction check
---> Package python-pycparser.noarch 0:2.14-1.el7 will be installed
--> Processing Dependency: python-ply for package: python-pycparser-2.14-1.el7.noarch
--> Running transaction check
---> Package python-ply.noarch 0:3.4-11.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================================
 Package                                                   Arch                                        Version                                             Repository                                    Size
==============================================================================================================================================================================================================
Installing:
 ansible                                                   noarch                                      2.4.2.0-2.el7                                       extras                                       7.6 M
Installing for dependencies:
 python-babel                                              noarch                                      0.9.6-8.el7                                         base                                         1.4 M
 python-cffi                                               x86_64                                      1.6.0-5.el7                                         base                                         218 k
 python-enum34                                             noarch                                      1.0.4-1.el7                                         base                                          52 k
 python-httplib2                                           noarch                                      0.9.2-1.el7                                         extras                                       115 k
 python-idna                                               noarch                                      2.4-1.el7                                           base                                          94 k
 python-jinja2                                             noarch                                      2.7.2-2.el7                                         base                                         515 k
 python-markupsafe                                         x86_64                                      0.11-10.el7                                         base                                          25 k
 python-paramiko                                           noarch                                      2.1.1-9.el7                                         updates                                      269 k
 python-passlib                                            noarch                                      1.6.5-2.el7                                         extras                                       488 k
 python-ply                                                noarch                                      3.4-11.el7                                          base                                         123 k
 python-pycparser                                          noarch                                      2.14-1.el7                                          base                                         104 k
 python2-cryptography                                      x86_64                                      1.7.2-2.el7                                         base                                         502 k
 python2-jmespath                                          noarch                                      0.9.0-3.el7                                         extras                                        39 k
 python2-pyasn1                                            noarch                                      0.1.9-7.el7                                         base                                         100 k
 sshpass                                                   x86_64                                      1.06-2.el7                                          extras                                        21 k

Transaction Summary
==============================================================================================================================================================================================================
Install  1 Package (+15 Dependent packages)

Total download size: 12 M
Installed size: 57 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/python-babel-0.9.6-8.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY                                  ]  0.0 B/s | 574 kB  --:--:-- ETA 
Public key for python-babel-0.9.6-8.el7.noarch.rpm is not installed
(1/16): python-babel-0.9.6-8.el7.noarch.rpm                                                                                                                                            | 1.4 MB  00:00:00     
(2/16): python-idna-2.4-1.el7.noarch.rpm                                                                                                                                               |  94 kB  00:00:00     
(3/16): python-enum34-1.0.4-1.el7.noarch.rpm                                                                                                                                           |  52 kB  00:00:00     
Public key for python-httplib2-0.9.2-1.el7.noarch.rpm is not installed                   13% [==========-                                                                   ] 1.5 MB/s | 1.6 MB  00:00:06 ETA 
(4/16): python-httplib2-0.9.2-1.el7.noarch.rpm                                                                                                                                         | 115 kB  00:00:00     
(5/16): python-jinja2-2.7.2-2.el7.noarch.rpm                                                                                                                                           | 515 kB  00:00:00     
(6/16): python-passlib-1.6.5-2.el7.noarch.rpm                                                                                                                                          | 488 kB  00:00:00     
Public key for python-paramiko-2.1.1-9.el7.noarch.rpm is not installed
(7/16): python-paramiko-2.1.1-9.el7.noarch.rpm                                                                                                                                         | 269 kB  00:00:00     
(8/16): python-ply-3.4-11.el7.noarch.rpm                                                                                                                                               | 123 kB  00:00:00     
(9/16): python-pycparser-2.14-1.el7.noarch.rpm                                                                                                                                         | 104 kB  00:00:00     
(10/16): python2-cryptography-1.7.2-2.el7.x86_64.rpm                                                                                                                                   | 502 kB  00:00:00     
(11/16): python2-pyasn1-0.1.9-7.el7.noarch.rpm                                                                                                                                         | 100 kB  00:00:00     
(12/16): python2-jmespath-0.9.0-3.el7.noarch.rpm                                                                                                                                       |  39 kB  00:00:00     
(13/16): sshpass-1.06-2.el7.x86_64.rpm                                                                                                                                                 |  21 kB  00:00:00     
(14/16): ansible-2.4.2.0-2.el7.noarch.rpm                                                                                                                                              | 7.6 MB  00:00:03     
(15/16): python-cffi-1.6.0-5.el7.x86_64.rpm                                                                                                                                            | 218 kB  00:00:04     
(16/16): python-markupsafe-0.11-10.el7.x86_64.rpm                                                                                                                                      |  25 kB  00:00:04     
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                         1.8 MB/s |  12 MB  00:00:06     
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-6.1810.2.el7.centos.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : python2-pyasn1-0.1.9-7.el7.noarch                                                                                                                                                         1/16 
  Installing : python-enum34-1.0.4-1.el7.noarch                                                                                                                                                          2/16 
  Installing : python-httplib2-0.9.2-1.el7.noarch                                                                                                                                                        3/16 
  Installing : sshpass-1.06-2.el7.x86_64                                                                                                                                                                 4/16 
  Installing : python-babel-0.9.6-8.el7.noarch                                                                                                                                                           5/16 
  Installing : python2-jmespath-0.9.0-3.el7.noarch                                                                                                                                                       6/16 
  Installing : python-passlib-1.6.5-2.el7.noarch                                                                                                                                                         7/16 
  Installing : python-ply-3.4-11.el7.noarch                                                                                                                                                              8/16 
  Installing : python-pycparser-2.14-1.el7.noarch                                                                                                                                                        9/16 
  Installing : python-cffi-1.6.0-5.el7.x86_64                                                                                                                                                           10/16 
  Installing : python-markupsafe-0.11-10.el7.x86_64                                                                                                                                                     11/16 
  Installing : python-jinja2-2.7.2-2.el7.noarch                                                                                                                                                         12/16 
  Installing : python-idna-2.4-1.el7.noarch                                                                                                                                                             13/16 
  Installing : python2-cryptography-1.7.2-2.el7.x86_64                                                                                                                                                  14/16 
  Installing : python-paramiko-2.1.1-9.el7.noarch                                                                                                                                                       15/16 
  Installing : ansible-2.4.2.0-2.el7.noarch                                                                                                                                                             16/16 
  Verifying  : python-idna-2.4-1.el7.noarch                                                                                                                                                              1/16 
  Verifying  : python-markupsafe-0.11-10.el7.x86_64                                                                                                                                                      2/16 
  Verifying  : python-jinja2-2.7.2-2.el7.noarch                                                                                                                                                          3/16 
  Verifying  : python-ply-3.4-11.el7.noarch                                                                                                                                                              4/16 
  Verifying  : python-passlib-1.6.5-2.el7.noarch                                                                                                                                                         5/16 
  Verifying  : python2-jmespath-0.9.0-3.el7.noarch                                                                                                                                                       6/16 
  Verifying  : python-paramiko-2.1.1-9.el7.noarch                                                                                                                                                        7/16 
  Verifying  : python-babel-0.9.6-8.el7.noarch                                                                                                                                                           8/16 
  Verifying  : ansible-2.4.2.0-2.el7.noarch                                                                                                                                                              9/16 
  Verifying  : python-cffi-1.6.0-5.el7.x86_64                                                                                                                                                           10/16 
  Verifying  : sshpass-1.06-2.el7.x86_64                                                                                                                                                                11/16 
  Verifying  : python-httplib2-0.9.2-1.el7.noarch                                                                                                                                                       12/16 
  Verifying  : python2-pyasn1-0.1.9-7.el7.noarch                                                                                                                                                        13/16 
  Verifying  : python-enum34-1.0.4-1.el7.noarch                                                                                                                                                         14/16 
  Verifying  : python-pycparser-2.14-1.el7.noarch                                                                                                                                                       15/16 
  Verifying  : python2-cryptography-1.7.2-2.el7.x86_64                                                                                                                                                  16/16 

Installed:
  ansible.noarch 0:2.4.2.0-2.el7                                                                                                                                                                              

Dependency Installed:
  python-babel.noarch 0:0.9.6-8.el7        python-cffi.x86_64 0:1.6.0-5.el7              python-enum34.noarch 
登录查看全部

参与评论

评论留言

还没有评论留言,赶紧来抢楼吧~~

手机查看

返回顶部

给这篇文章打个标签吧~

棒极了 糟糕透顶 好文章 PHP JAVA JS 小程序 Python SEO MySql 确认