自动化运维工具ansible学习

ansible是自动化运维工具,基于python。实现了批量系统配置、程序部署、运行命令等功能。
ansible是基于模块工作的,本身没有批量部署能力,真正具有批量部署的是ansible所运行的模块,ansible只是提供了一个框架。
主要包括:
1.连接插件connnection plugins 复制和被监听端实现通信
2.host inventory 指定操作的主机,是一个配置文件里面定义监控的主机
3.各种核心模块、command模块、自定义模块
4.借助于插件完成记录日志等功能
5.playbook 执行多个任务时,可以让节点一次性运行多个任务
先配置组 vim /etc/ansible/hosts
[cluster]
10.114.0.1
10.114.0.3

ansible中默认的模块是 -m command 所以此参数不用填写,直接使用即可
缺点:不支持管道,无法批量执行任务
查看cluster组所有用户的ifconfig:
ansible cluster -m command -a 'ifconfig'
copy模块:从主机拷贝文件到节点
ansible cluster -m copy -a "src=/tmp/1.txt dest=/tmp"
shell模块:执行shell脚本
ansible cluster -m shell -a "/tmp/a.sh"
raw模块:支持管道命令
ansible cluster -m raw -a "ifconfig|grep eth0"
file模块:修改文件属性
ansible cluster -m file -a "dest=/tmp/a.sh mode=700 owner=root group=root"
ping 模块:检查节点是否能ping通
ansible cluster -m ping
apt模块:安装软件
ansible cluster -m apt -a "update_cache=yes" 更新源
ansible cluster -m apt -a "name=ntp state=latest" 安装最新版本的软件


猜你喜欢

转载自blog.csdn.net/qq_23348071/article/details/73800912