Ansible 在云环境中的使⽤用
扇⻉贝⺴⽹网
关于扇⻉贝⺴⽹网
扇⻉贝是最⼤大的英语学习⺴⽹网站和社区
扇⻉贝提供单词,听⼒力,炼句,新闻和读书的 APP
1000 万⽤用户
50万⽇日活
60 台云服务器
什么是 Ansible
Ansible is the simplest way to automate
Simple: Automate in hours - not weeks - with Ansible's human-readable IT automation language.
Agentless: Ansible uses SSH instead of agents. More efficient, more secure and less to manage.
Powerful: App deployment, configuration management and orchestration - all from one system.
什么是 Ansible
⾃自动化运维⼯工具
通过配置⽂文件,不是脚本,管理远程服务器
基于 ssh ⽽而不是基于 agent ,区别于 puppet
和 saltstack
ansible ⼯工作条件
所以通过ssh 完成的事情 ansible 都可以:
1.远程机器是 开机的, 云服务器有这个优势
2.需要能够通过 ssh 访问远程机器
3.为了操作⽅方便,ssh ⽤用户需要没有密码的sudo
权限
Ansible 和 saltstack/puppet 区别
1.没有具体使⽤用过基于 ruby 的 puppet, 最有历
史的⾃自动化运维⼯工具
2. saltstack 需要在远程机器上安装 agent,
agent 需要安装在 root 账户下, agent 有时会
⾮非常占⽤用内存, 不适合内存⼩小 (512M) 的云机
器
3. ansible 是完全基于 ssh, 只需要在控制机器上
安装,⽅方便实⽤用
Ansible 具体可以做什么事情
ssh 能做的都可以,我常⽤用的⼀一些命令:
1. apt-get
2. pip
3. iptables
4. mount
5. crontab
6. copy
⼀一些例⼦子
ansible-playbook
执⾏行 ansible 配置⽂文件的⽅方法。
Ansible 配置⽂文件就是把在把远程机器上的命令
⽤用配置⽂文件描述出来
ansible-play /ansible/playbooks/iptables/
⼀一个实例
另外⼀一个实例
这⾥里的⽅方法是错误的,应当⽤用 apt-key
除了⾃自动化,还有什么好处
1.配置⽂文件都可以/应当放在 git 上
1.可以 trace ⽂文件的改动
1.不容易出现⼈人为的错误
关于我
吴焱红
本⼈人对运维,前端和python 都很有兴趣,欢迎
⼀一起讨论,或者加⼊入我的团队