ansible入门

 

前言:

ansible能做什么,最常用的就是批量部署,批量下发配置,批量执行程序等等。最常见的的模式就是通过SSH去控制待更新的机器。

 

(1)安装方法很多种

简单的pip安装:pip install ansible

 

(2)配置SSH公钥秘钥无密码登陆

参考文章:ssh公钥密钥无密码登陆

 

(3)配置ansible hosts文件/etc/ansible/hosts(此乃默认路径,也可以使用-i指定其他路径),32323是我客户机的SSH端口,108是我客户机的IP

 

[test-ping]
192.168.1.108:32323

[test-copy]
192.168.1.108:32323

[test-command]
192.168.1.108:32323

[test-shell]
192.168.1.108:32323


(4)查看ansible手册

 

ansible --help

 

(5)列出ansible模块

ansible-doc -l

 

(6)查看模块用法,比如查看ping模块用法

ansible-doc ping

 

(7)常用的模块,比如ping、copy、command、shell等等

 

(8)例子,先ping客户机,然后准备一个t.sh文件,然后将t.sh拷贝至客户机,更改权限后运行,并观察结果

 

t.sh

#! /bin/sh
echo "hello world"

 

 

 

 

ansible test-ping -m ping

ansible test-copy -m copy -a "src=~/t.sh dest=~/t.sh"

ansible test-command -m command -a "chmod +x ~/t.sh"

ansible test-shell -m shell -a "~/t.sh"

 

 

ansible功能非常强大,这里不深入展开,更多资料请参考官网:https://www.ansible.com/

 

原文出自:http://blog.csdn.net/daiyudong2020/article/details/70234316
 

 

End;

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值