由于centos7预装了python,因此我们可以跳过python的安装环节(记得关闭防火墙)

  1. [root@model ~]#
  2. [root@model ~]# python --version
  3. Python 2.7.
  4. [root@model ~]#

本文使用yum安装ansible

  1. [root@model ~]# yum install epel-release
  1. [root@model ~]# yum install ansible

配置目标服务器192.168.1.10和192.168.1.20(在文件中添加红色部分)

  1. [root@model ~]# vi /etc/ansible/hosts
  2. # This is the default ansible 'hosts' file.
  3. #
  4. # It should live in /etc/ansible/hosts
  5. #
  6. # - Comments begin with the '#' character
  7. # - Blank lines are ignored
  8. # - Groups of hosts are delimited by [header] elements
  9. # - You can enter hostnames or ip addresses
  10. # - A hostname/ip can be a member of multiple groups
  11.  
  12. # Ex : Ungrouped hosts, specify before any group headers.
  13.  
  14. ## green.example.com
  15. ## blue.example.com
  16. ## 192.168.100.1
  17. ## 192.168.100.10
  18.  
  19. # Ex : A collection of hosts belonging to the 'webservers' group
  20.  
  21. ## [webservers]
  22. ## alpha.example.org
  23. ## beta.example.org
  24. ## 192.168.1.100
  25. ## 192.168.1.110
  26.  
  27. # If you have multiple hosts following a pattern you can specify
  28. # them like this:
  29.  
  30. ## www[:].example.com
  31.  
  32. # Ex : A collection of database servers in the 'dbservers' group
  33.  
  34. ## [dbservers]
  35. ##
  36. ## db01.intranet.mydomain.net
  37. ## db02.intranet.mydomain.net
  38. ## 10.25.1.56
  39. ## 10.25.1.57
  40.  
  41. # Here's another example of host ranges, this time there are no
  42. # leading 0s:
  43.  
  44. ## db-[:]-node.example.com
  45.  
  46. 192.168.1.10
  47. 192.168.1.20
  48.  
  49. ~
  50. ~
  51. ~
  52. ~
  53. ~
  54. ~
  55. "/etc/ansible/hosts" 47L, 1041C

生成SSH密钥

  1. [root@model ~]# ssh-keygen -t rsa

将/root/.ssh目录下的id_rsa.pub拷贝到目标服务器

  1. [root@model ~]# scp /root/.ssh/id_rsa.pub root@192.168.1.10:/root/.ssh/authorized_keys
  1. [root@model ~]# scp /root/.ssh/id_rsa.pub root@192.168.1.20:/root/.ssh/authorized_keys

测试批量执行ping命令

  1. [root@model ~]#
  2. [root@model ~]# ansible all -m ping
  3. 192.168.1.10 | SUCCESS => {
  4. "changed": false,
  5. "ping": "pong"
  6. }
  7. 192.168.1.20 | SUCCESS => {
  8. "changed": false,
  9. "ping": "pong"
  10. }
  11. [root@model ~]#

至此,ansible安装完成~

centos7下安装ansible的更多相关文章

  1. CentOS7 下 安装 supervisor以及使用

    CentOS7 下 安装 supervisor 以及使用 手动安装 [注] linux环境必须安装 python 1.获取supervisor包:[https://pypi.python.org/py ...

  2. Linux CentOs7 下安装 redis

    Linux CentOs7 下安装 redis 请将以下命令放入linux命令行中运行 如果安装过程前没有安装GCC请先安装  命令如下 $ yum install gcc-c++ $ wget ht ...

  3. Centos7下安装配置Redsocks

    Redsocks是一个开源的网络程序,代码依赖开源的libevent网络库.Redsocks允许你将所有TCP连接重定向到SOCKS或HTTPS代理,比如Shadowsocks(Centos7下安装配 ...

  4. CentOS7下安装SVN服务端

    CentOS7下安装SVN服务 1. yum命令即可方便的完成安装# sudo yum install subversion 测试安装是否成功:# svnserve --version 更改svn的默 ...

  5. centOS7下安装GUI图形界面

    1.如何在centOS7下安装GUI图形界面 当你安装centOS7服务器版本的时候,系统默认是不会安装GUI的图形界面程序,这个需要手动安装CentOS7 Gnome GUI包. 2.在系统下使用命 ...

  6. CentOS7下安装MySQL并配置远程连接

    一.CentOS7下安装MySQL数据库 CentOS7默认的安装包里面已经没有 MySQL-Server安装包了,远程镜像中也没有了. 默认的是MariaDB (MySQL的一个分支,开发这个分支的 ...

  7. Docker学习笔记3:CentOS7下安装Docker-Compose

    Docker-Compose是一个部署多个容器的简单但是非常必要的工具. 安装Docker-Compose之前,请先安装 python-pip,请参考我的另一篇博文CentOS7下安装python-p ...

  8. docker(一) Centos7下安装docker

    docker(一) Centos7下安装dockerdocker(二) windows10下安装dockerdocker(三) 镜像和容器常用命令 docker(四) 使用Dockerfile构建镜像 ...

  9. centos7 下 安装部署nginx

    centos7 下 安装部署nginx 1.nginx安装依赖于三个包,注意安装顺序 a.SSL功能需要openssl库,直接通过yum安装: #yum install openssl b.gzip模 ...

随机推荐

  1. ➡️➡️➡️leetcode 需要每天打卡,养成习惯

    目录 待完成的 完成的 0204 0203 以前 java 的 ! 的操作 不像 c 那样自由,!不要使用在int 变量上 c ^ 是异或操作 体会:c中,malloc 后的新建的数组,默认不是0(j ...

  2. DRF项目之序列化器和视图重写方法的区别

    我们,都知道,DRF框架是一款高度封装的框架. 我们可以通过重写一些方法来实现自定义的功能. 今天,就来说说在视图中重写和序列化器中重写方法的区别. 在视图中重写方法: 接收请求,处理数据(业务逻辑) ...

  3. luogu P4013 数字梯形问题

    三倍经验,三个条件,分别对应了常见的3种模型,第一种是限制每个点只能一次且无交点,我们可以把这个点拆成一个出点一个入点,capacity为1,这样就限制了只选择一次,第二种是可以有交点,但不能有交边, ...

  4. redis集群在线迁移

    地址规划 主机名 ip地 端口 redis01 10.0.0.10 6379.6380 redis02 10.0.0.60 6379.6380 redis03 10.0.0.61 6379.6380 ...

  5. 使用C语言实现文件的操作

    #include <stdio.h> int main(int argc, char* argv[]) { // 创建文件类型 FILE* file; char buf[1024] = { ...

  6. 九 SpringMvc与json交互

    将json输出到页面: 1 加入jar包 2 配置Controller层,开启注解ResponseBody,将json发送到页面: 3 访问url 4 响应json,在形参列表里面加上注解

  7. java比较器Comparator

    1. 实现比较类 public class Comparator implements java.util.Comparator<TaskInfo>{ @Override public i ...

  8. c# 事件3

    1.什么是事件,使对象或者类具有通知功能的成员.//为了解决字段在外部被滥用,推出了事件 事件的功能能=通知+可选的事件参数(具体的详细信息,包括谁发送了消息,发送的什么消息) 使用:用于对象或者类件 ...

  9. LeetCode206. Reverse Linked List(反转链表)

    题目链接:https://leetcode.com/problems/reverse-linked-list/ 方法一:迭代反转 https://blog.csdn.net/qq_17550379/a ...

  10. 初识Prometheus

    安装Prometheus Server Prometheus基于Golang编写,编译后的软件包,不依赖于任何的第三方依赖.用户只需要下载对应平台的二进制包,解压并且添加基本的配置即可正常启动Prom ...