1、首先安装一下ansible

yum install ansible

2、修改一下ansible的参数以防ssh过去的时候需要首次判断yes  或者no

sed -i 's/#host_key_checking = False/host_key_checking = False/g' /etc/ansible/ansible.cfg

3、新建一个工作目录,写一个hosts文件 用来配置hosts

[root@192 et]# cat hosts
[own_host]
web.ansible.bd.com

4、新建一个screen.yml文件,先比如安装一个screen,内容如下

- name: Install screen
hosts: own_host
tasks:
- name: start install screen
yum:
name: screen
state: installed

5、执行安装之前要做好ssh免密

ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.0.100
[root@web ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
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:HC81CyaFnd4u2uxEhIg6CEISxw+XN/t4hP1vxfkbohY root@web.ansible.bd.com
The key's randomart image is:
+---[RSA 2048]----+
|o+. . o.. |
|o.o.o.+oo |
|o .+..o*=.o |
|+. . o=+=.o |
|+ +Soo . . |
| . ..+.oE + |
| =.. ..o o |
| ..o .+ . o|
| .. .o ..|
+----[SHA256]-----+
[root@web ~]#

[root@web ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.0.100
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.0.100 (192.168.0.100)' can't be established.
ECDSA key fingerprint is SHA256:bqCO0nWIDL1xZsor1O5E819ZLoV2aE+TDOmiKNBM+sQ.
ECDSA key fingerprint is MD5:21:18:a5:32:7f:9e:0e:48:41:d7:86:21:2a:36:8a:ee.
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@192.168.0.100's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh '192.168.0.100'"
and check to make sure that only the key(s) you wanted were added. [root@web ~]#


6、执行批量安装

ansible-playbook -i /opt/et/hosts /opt/et/screen.yml
[root@web ~]# ansible-playbook -i /opt/et/hosts /opt/et/screen.yml

PLAY [Install screen] *********************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************
ok: [web.ansible.bd.com] TASK [start install screen] ***************************************************************************************************************************************************************
changed: [web.ansible.bd.com] PLAY RECAP ********************************************************************************************************************************************************************************
web.ansible.bd.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 [root@web ~]#

最新文章

  1. [C#] 日志类
  2. 码云以及git使用
  3. RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.0 版本新增序列管理
  4. JavaScript很牛
  5. [No00001C]不想背单词患者的福音!-快来定制你的个性词包-不想记、记不牢,这可怎么办?
  6. shell实现https登录
  7. 一个DataTable赋值给另一个DataTable的常用方法
  8. 重复数据插入unique列时,锁加在哪?
  9. 适合自己的vim配置文件
  10. ubuntu下的notepad++
  11. thinkphp框架的相关总结
  12. AutoLayout 之NSLayoutConstraint
  13. svn恢复到某一版本
  14. 为什么公司宁愿 25K 重新招人,也不给你加到 20K?原因太现实……
  15. nagios的安装与部署
  16. Python 反射机制之hasattr()、getattr()、setattr() 、delattr()函数
  17. MacBook使用笔记2 - 安装windows虚拟机攻略
  18. 文件流 io.StringIo()
  19. CH4901 关押罪犯
  20. Revit Family API 找到实体某一方向上的面。

热门文章

  1. Android工程师所必经的三个阶段,你到哪个阶段了?
  2. 跟我一起写 Makefile(五)
  3. 让Dev支持C++11特性
  4. iOS开发之GIF转MP4
  5. cpu设计实践1
  6. kivy之TextInput属性实操练习
  7. noip15
  8. FPGA学习过程(二)
  9. 【译】JavaScript async / await:好的部分,陷阱和如何使用
  10. Windows下NodeJS安装与npm环境变量配置