安装和使用ansible

本文介绍了如何在Ubuntu环境中安装Ansible,并通过配置hosts文件和免密登录管理46台Linux服务器。通过分发文件和执行shell命令,实现对所有服务器安装EDR的过程。

目的:

迁移到新的环境后,linux共46台,需要统一管理

参考连接:

https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-on-ubuntu

 

安装ansible:

Control环境为ubuntu,在官网上选择ubuntu安装方式,如下图

 

   47  apt update

   48  apt install software-properties-common

   49  apt-add-repository --yes --update ppa:ansible/ansible

   50  apt install ansible

安装好后,可执行ansible --version查看安装版本

 

为了方便管理,对涉及到的被控端添加免密登录

   77  ssh-keygen -t rsa -f /root/.ssh/id_rsa -N ''

   78  ls /root/.ssh/

   79  ssh-copy-id x.x.x.x

在ansible的hosts下编排主机分组,这里全部用分组来管理,更方便

 

此处分为5组:

[testserver] #做测试的分组

[hlwubuntu] #互联网下所有ubuntu服务器分组

[zwwwubuntu] #政务网下所有ubuntu服务器分组

[jszxcentos] #计算分组

[allserver] #所有服务器分组

利用ansible对所有被控端安装EDR

先将文件分发下去

root@ansible:/mnt/tool# ansible allserver -m synchronize -a "src=/mnt/tool/edr dest=/opt/"

在执行安装

root@ansible:/mnt/tool# ansible allserver -m shell -a "cd /opt/edr/ && chmod +x install_edr.sh && ./install_edr.sh"

 

*这里分发文件不用copy,是因为copy文件一直失败,原因暂时未锁定。

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值