Ansible是一款简单的运维自动化工具,只需要使用ssh协议连接就可以来进行系统管理,自动化执行命令,部署等任务。
命令模块
command
shell
文件模块
copy
fetch
file
安装模块
yum
服务模块
service
挂载模块
mount
定时任务
cron
用户模块
group
user
压缩解压
unarchive
> yum install ansible -y
> vim /etc/ansible/hosts
[web]
192.168.2.10 ansible_ssh_port=22 ansible_ssh_user=rumenz ansible_ssh_pass="123456"
192.168.2.11 ansible_ssh_port=22 ansible_ssh_user=rumenz ansible_ssh_pass="123456"
我们定义了一个web组(可以加很多主机),Ansible默认使用的是ssh协议,指定好端口,账号,密码就可以了。
除了使用账号,密码的形式配置,我们也可以用秘钥,后面访问。
> ansible web -m ping
web就是上面我们定义的分组,-m我后面指定模块,这里我们使用ping模块,用于查看主机是否网络可达。
> ansible web -m shell -a "pwd"
这里我们使用的是shell 模块,-a后面跟上需要执行的shell命令
> ansible web -m shell -a "ps -ef | grep nginx"
> ansible web -m shell -a "yum install redis -y"
注意复杂的软件安装,需要编写Ansible playbook配置文件,更加灵活。
原文链接:https://rumenz.com/rumenbiji/linux-ansible-quick.html
页面更新:2024-06-16
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号