首页 > 其他 > 详细

ansble 基本上操作

时间:2020-05-01 00:45:03      阅读:90      评论:0      收藏:0      [点我收藏+]

安装ansible

yum install ansble

ansible用ssh管理主机,配置成密钥模式来管理节点主机

[root@centos01 ~]# ssh-keygen -t rsa  <!--生成密钥对-->
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):<!--密钥对存放路径-->
Created directory /root/.ssh.
Enter passphrase (empty for no passphrase):
       <!--输入私钥保护密码,直接按Enter键表示无密码-->
Enter same passphrase again:    <!--再次输入-->
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:cJz6NRTrvMDxX+Jpce6LRnWI3vVEl/zvARL7D10q9WY root@centos01
The keys randomart image is:
+---[RSA 2048]----+
|          .   . .|
|       . . +   oo|
|      . = o o. oo|
|       = * o..+ *|
|      . S *.=+=*+|
|       . o =+XooE|
|        . ..=.++.|
|           ..o ..|
|           .. o. |
+----[SHA256]-----+

上传公钥到节点主机

ssh-copy-id -i .ssh/id_rsa.pub  root@192.168.100.20

管理节点的命令

ansible -i /etc/ansible/hosts web -m ping     #/etc/ansible/hosts节点管理路径, web组

[root@centos01 ~]# vim /etc/ansible/hosts
............   <!--此处省略部分内容-->
[web]
192.168.100.20
192.168.100.30
[test]
www.benet.com:222                         <!--通过222端口管理设备-->
[mail]
yj1.kgc.cn
yj[2:5].kgc.cn
<!--[2:5]表示2~5之间的所有数字,即表示yj2.kgc.cn、yj3.kgc.cn……的所有主机-->

ansible web -m command -a "systemctl status httpd" --limit "192.168.100.20"  #发送命令给web组192.168.100.20节点主机

ansible web -m command -a "systemctl status httpd" #发送命令给web组的所有主机

 

ansble 基本上操作

原文:https://www.cnblogs.com/yunweiweb/p/12812233.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!