学习ansible

ansible总结

 

ansible基本用法:

 

1、ansible运行环境:

需要主机中安装有python及ssh,一般linux都已预装。

配置ssh启用公钥认证免密登陆远程主机,否则运行ansible需要输入远程主机用户密码。

 

redhat系列可直接使用yum安装yum -y install ansible

安装后/etc/ansible 目录下有两个文件 ansible.cfg、hosts

在hosts文件中定义好要批量管理的主机清单。

 

 

ansible 命令后接“一组主机的名称”,也可以用all或*表示所有主机  -m 指定模块, -a 指定参数

例:运行两条命令,显示所有webserver的主机型号、序列号,然后关机。

ansible  webservers -m shell -a "dmidecode -t1 | grep -2 'Product Name'"

ansible  webservers -m command -a "shutdown -h now"

猜你喜欢

转载自www.cnblogs.com/ValyrianSteel/p/12411687.html