准备至少两台机器 Centos7,这两台机器都关闭 selinux

IP:106.13.118.132   服务端(ansible)   master
IP:148.70.60.244    节点          slaver

服务端:

1、Ansible仓库默认不在yum仓库中,因此我们需要使用下面的命令启用epel仓库
[root@master tools]# yum install -y epel-release

2、安装ansible
[root@master tools]# yum install -y ansible

3、查看ansible版本:
[root@master tools]# ansible --version
ansible 2.7.10
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Apr 11 2018, 07:36:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]

4、使用ssh-keygen生成公钥
[root@master tools]# ssh-keygen -P ''
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:OAgDBVATJg64cl++LrvxVbxYyFDp0joX0eps5mpd2ME root@master
The key's randomart image is:
+---[RSA 2048]----+
|O+*. .o |
|++ . .o . |
| oo .o + |
|o .o .o+=oE |
|.. ..oo=S++. |
| . +.B+o. |
| . Oo.. |
| .oo.o |
| o*+. |
+----[SHA256]-----+
[root@master tools]# systemctl stop firewalld.service

5、使用ssh-copy-id命令来复制ansible公钥的公钥到节点中,实现无秘钥执行命令
[root@master tools]# ssh-copy-id -i root@148.70.60.244
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '148.70.60.244 (148.70.60.244)' can't be established.
ECDSA key fingerprint is SHA256:EXMPsKuf0hIIw0Ena8RDnYjm99CoYSqWzX9Nzw0OpxE.
ECDSA key fingerprint is MD5:0f:3b:7f:30:e7:0e:12:83:ea:4c:be:b1:d9:03:57:ef.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@148.70.60.244's password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh 'root@148.70.60.244'"
and check to make sure that only the key(s) you wanted were added.

6、输入正确的节点登录密码,测试是否无需密码登录节点
[root@master tools]# ssh root@148.70.60.244
Last login: Thu Apr 25 15:29:42 2019 from 211.137.135.200

7、ctrl+d 退出 服务端 在ansible节点上添加可控制节点,/etc/ansible/hosts ansible的配置文件相对于简单所定义主机可以在webservers中定义节点ip
[root@master tools]# vim /etc/ansible/hosts

[testservers]
148.70.60.244

8、保存退出无需重启服务,测试是否成功
[root@master tools]# ansible -m ping 'testservers'
148.70.60.244 | SUCCESS => {
"changed": false,
"ping": "pong"
}

ansible 服务端执行命令:

[root@master tools]# ansible -m command -a "uptime" 'testservers'

148.70.60.244 | CHANGED | rc=0 >>
16:24:02 up 59 min, 2 users, load average: 0.24, 0.06, 0.06

[root@master tools]# ansible -m command -a "uname -r" 'testservers'
148.70.60.244 | CHANGED | rc=0 >>
3.10.0-514.26.2.el7.x86_64

[root@master tools]#
[root@master tools]# ansible -m command -a "yum install -y telnet*" 'testservers'

9、节点:
[root@slaver tools]# yum install -y epel-release
[root@slaver tools]# yum install -y ansible
[root@slaver tools]# ansible --version
ansible 2.7.10
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
[root@slaver tools]# systemctl stop firewalld.service

节点侧验证 Telnet:
[root@slaver tools]# telnet 106.13.118.132 22
Trying 106.13.118.132...
Connected to 106.13.118.132.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.4

Centos7安装配置ansible运维自动化工具的更多相关文章

  1. Ansible运维自动化工具19个常用模块使用实例【转】

    一.模块列表 1.setup 2.ping 3.file 4.copy 5.command 6.shell 7.script 8.cron 9.yum 10.service 11.group 12.u ...

  2. Ansible运维自动化工具

    1>Ansible 1>ansible简介 ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabri ...

  3. Centos7搭建ansible运维自动化工具

    1)设置主机名和hosts文件 2)配置阿里云repo源 Wget -O /etc/yum.repos.d/aliyun.repo https://mirrors.aliyun.com/repo/Ce ...

  4. Ansible 运维自动化 ( 配置管理工具 )

    背景 出差背景,要搞项目的自动化部署.因为只直接对接生产分发,机器又非常多,这样以往使用的bat只能作为应急方案了,还是得考虑使用专业化的工具来做这个事情! 当下有许多的运维自动化工具( 配置管理 ) ...

  5. Ansible运维自动化

    Ansible运维自动化 一.Ansible-playbook的初步使用 playbook的使用,playbook可以把ansible的模块进行组合 ln -s /usr/local/python/b ...

  6. 运维自动化工具ansible

    企业级自动化运维工具应用实战ansible 公司计划在年底做一次大型市场促销活动,全面冲刺下交易额,为明年的上市做准备.公司要求各业务组对年底大促做准备,运维部要求所有业务容量进行三倍的扩容,并搭建出 ...

  7. 使用Chef管理windows集群 | 运维自动化工具

    但凡服务器上了一定规模(百台以上),普通的ssh登录管理的模式就越来越举步维艰.试想Linux发布了一个高危漏洞的补丁,你要把手下成百上千台机器都更新该补丁,如果没有一种自动化方式,那么至少要耗上大半 ...

  8. 运维自动化工具 Cobbler

    简介: 关于操作系统安装方面的自动化,早前我们使用 RedHat 推出的 Kickstart 来批量安装操作系统,近年来 RedHat 又推出一个 Cobbler . Cobbler 使用 Pytho ...

  9. 运维自动化工具---Puppet

    案例环境:-----------------------------------------------------------------主机  操作系统   IP地址  主要软件--------- ...

随机推荐

  1. 刷题总结——天使玩偶(bzoj2716)

    题目: Description Input Output HINT 题解: 学了cdq后近期最后一道题···然而tm还是搞了1个半小时才tm搞出来······ 先说思路:对于绝对值,我们采取类似于旋转 ...

  2. 337. House Robber III(包含I和II)

    198. House Robber You are a professional robber planning to rob houses along a street. Each house ha ...

  3. 标准C程序设计七---33

    Linux应用             编程深入            语言编程 标准C程序设计七---经典C11程序设计    以下内容为阅读:    <标准C程序设计>(第7版) 作者 ...

  4. linux内核设计与实现第一章

    1.1 unix的历史 Thompson实现unix 伯克利大学对其进一步开发推出了著名的BSD 其他各大厂商相继推出自己的unix 1.1.2 unix的特性 unix系统是一个强大,健壮,稳定的操 ...

  5. yii加载自带验证码的方法

    Yii的源码包里面是自带有验证码的相关类的,因此在使用验证码的时候无需再加载外部验证码类来助阵了.下面本文将介绍一下如何在项目中加载Yii自带的验证码功能. 具体分三步: (1)在需要加载验证码的co ...

  6. IOS-input元素光标偏移乱跑,是什么原因

    这中情况只会出现在一些ios手机上,是兼容性的问题,当然我没有认真的确认过是出现在那些ios系统上的: 之所以出现这种情况,肯定是在input上或TA的父元素上用到了position:fixed; 目 ...

  7. VUE之命令行报错:Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead 解决办法

    Failed to compile. ./node_modules/vue-loader/lib/template-compiler?{"id":"data-v-5992 ...

  8. BZOJ 4326 NOIP2015 运输计划(二分答案 + 树上差分思想)

    题目链接  BZOJ4326 这个程序在洛谷上TLE了……惨遭卡常 在NOIP赛场上估计只能拿到95分吧= = 把边权转化成点权 首先求出每一条路径的长度 考虑二分答案,$check(now)$ 对于 ...

  9. Codechef Eugene and big number(矩阵快速幂)

    题目链接 Eugene and big number 题目转化为 $f(n) = m * f(n - 1) + a$ $f(n + 1) = m * f(n) + a$ 两式相减得 $f(n + 1) ...

  10. [原创][Verilog]个人.v文件书写规范

    1> 文件名命名,小些单词为主且从命名中可以大致读出其功能,例如:fpga_power.v,can_ctrl.v等命名. 2> 顶层top文件的输入输出IO信号使用大些表示,且加上”i/o ...