准备至少两台机器 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. BZOJ-1798 维护序列

    线段树.支持区间加.区间乘.区间查询和. 标记下移还有取模要注意. var n,p,q,i,s,t:longint; a:int64; num,n1,n2,n3:array[0..500000] of ...

  2. 使用router.push()进行页面跳转的问题

    看着官网的文档直接router.push()这样会报错router undefind,需要写成this.$router.push()才可以

  3. 【CF732D】Exams(线性扫描,贪心,二分)

    题意:有m门需要过的课程,n天的时间可以选择复习.考试(如果的d[i]为0则只能复习),一门课至少要复习a[i]天才能通过(可以不连续的复习得到a[i]),问最早什么时候可以把所有课程都通过,如果不能 ...

  4. Linux 之 文件搜索命令

    文件搜索命令 参考教程:[千峰教育] 文件搜索定位 grep: 作用:通用规则表达式分析程序,是一种强大的文本搜索工具, 它能使用正则表达式搜索文本,并把匹配的行打印出来. 格式:grep [选项] ...

  5. checkbox 复选框只能选中一次,之后不能用

    <td> <input type="checkbox" name="is_check" id="is_check" val ...

  6. datetimepicker[jquery-ui]时间控件的三种初始化方法

    1.只显示年月日 $( ".datepicker").datepicker({ needDay:true, changeMonth: true, //显示月份 changeYear ...

  7. 常用函数和STL

    #include <bits/stdc++.h> using namespace std; #define PI acos(-1.0) int main() { printf(" ...

  8. Android图片缓存之初识Glide(三)

    前言: 前面总结学习了图片的使用以及Lru算法,今天来学习一下比较优秀的图片缓存开源框架.技术本身就要不断的更迭,从最初的自己使用SoftReference实现自己的图片缓存,到后来做电商项目自己的实 ...

  9. arcgis andriod 加载影像

    MapView mMapView;......String rasterPath = Environment.getExternalStorageDirectory().getPath() + &qu ...

  10. RNN推导

    http://www.cnblogs.com/YiXiaoZhou/p/6058890.html RNN求解过程推导与实现 RNN LSTM BPTT matlab code opencv code ...