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 ~]#

ansible 批量安装yum包的更多相关文章

  1. Centos7 使用 Ansible 批量安装中文字体

    需求背景 Centos7 下 Java 生成图片水印时中文乱码,原因是没有安装中文字体. 安装中文字体 以下是基于 Centos7 手动安装中文字体的详细步骤.当测试或者生产环境服务器比较多的时候,建 ...

  2. Pip批量安装/卸载包

    pip批量安装package 将需要安装的包保存在requirements.txt中 cd到aa.txt所在目录,运行: pip install -r requirements.txt pip批量卸载 ...

  3. ansible 批量安装zabbix agentd客户端

    目录结构 # tree /etc/ansible/ /etc/ansible/ ├── ansible.cfg ├── hosts ├── roles │   └── zabbix-agentd │  ...

  4. linux 值安装yum包

    1. 创建文件,挂载  rhel7-repo-iso [root@rhel7 ~]# mkdir /media/rhel7-repo-iso [root@rhel7 ~]# mount /dev/cd ...

  5. Centos 安装yum,安装ansible

    今天使用centos安装ansible,发现域名默认安装是未注册的.提示: This system is not registered to Red Hat Subscription Manageme ...

  6. Python Python实现批量安装android apk包

    基于Python实现批量安装android apk包 by:授客 QQ:1033553122 1.相关软件包及文件下载 下载地址:adb软件包及批量安装apk包的py文件.zip 2.测试环境 Win ...

  7. Ansible批量自动化管理工具

    一,工具与环境介绍 1.1 ansible简介 批量管理服务器的工具 无需部署agent,通过ssh进行管理 流行的自动化运维工具:https://github.com/ansible/ansible ...

  8. linux运维、架构之路-ansible批量管理

    一.ansible软件 1.介绍 ①ansible是一个基于Python开发的自动化运维工具 ②其功能实现基于SSH远程连接服务 ③ansible可以实现批量系统配置.批量软件部署.批量文件拷贝.批量 ...

  9. CentOS下安装yum源的流程和操作

    一般公司都用Linux来搭建服务器,Linux安装软件时能够用yum安装依赖包是一件非常简单而幸福的事情,因为你只需一个简单的安装命令yum install []即可安装相应的软件,yum工具会自动的 ...

随机推荐

  1. Windows安装Hyper-V并优化部署Linux虚拟机

    安装Hyper-V 打开服务器管理器-->添加角色和功能-->下一步,选择Hyper-V,如图所示 然后一直默认往下走,一直到安装完成,然后重新启动计算机,如图所示 其中涉及的虚拟交换机. ...

  2. vue3.0安装

    一 .vue3.0安装 vue3.0安装 个人推荐以下2种 (1). 开发工具的对应代码中 插入CDN <script src="https://unpkg.com/vue@next& ...

  3. Matlab 使用filter求解系统响应

    MATLAB 提供了函数filter,可以实现差分方程的递规求解. 设差分方程的形式为\(a_0y(n) + a_1y(n-1) + \cdots + a_my(n-m)=b_0x(n)+b_1x(n ...

  4. Windows提权总结

    当以低权用户进去一个陌生的windows机器后,无论是提权还是后续做什么,第一步肯定要尽可能的搜集信息.知己知彼,才百战不殆. 常规信息搜集 systeminfo 查询系统信息 hostname 主机 ...

  5. 嵌入式Linux可用的防火墙——iptables:实现ip白名单、mac地址白名单

    iptables是linux系统下的一个功能强大的模块,不仅可以用作防火墙,还可以实现NAT等众多路由功能.iptables的容器有很清晰的层次关系: 1. iptables是表的容器,iptable ...

  6. JVM的GC机制

    JVM的GC机制 1. 什么对象会被回收 引用计数法:如果一个对象被引用一次,则记录引用次数加一,如果引用取消,则减一,当减到0时,需要被回收. 问题:循环引用,A引用B,B引用A,除此之外,已经无法 ...

  7. 浅谈 SQL 注入(注入篇)

    一.SQL注入简介 1.1 什么是SQL注入 在用户可控制的参数上过滤不严或没有任何限制,使得用户将传入的参数(如URL,表单,http header)与SQL语句合并构成一条 SQL语句传递给web ...

  8. Linux搭建VNC servere服务

    此安装方法只适用于centos7以上的版本 一,安装 以root用户运行以下命令来安装vncserver; yum install tigervnc-server  同样运行以下命令来安装vncvie ...

  9. FirstGradle

    一.导入依赖 二.build.gradle 整合SpringBoot plugins { id 'java' } group 'com.qiang' version '1.0.0-SNAPSHOT' ...

  10. 踩坑记录之 -- String.IndexOf 在 .Net5 和 .Netcore3 中返回值不一样

    .Net Core3.1 下 运行此段代码 class Program { static void Main(string[] args) { // .NET Core 3.1 string s = ...