1.ansible是啥?
ansible是运维自动化的基于Python的开源工具,具有批量处理,模块化特点,简化开发或运维人员的操作流程,减少重复的工作量。
ansible只是提供一种框架。主要包括:
(1)、连接插件connection plugins:负责和被监控端实现通信;
(2)、host inventory:指定操作的主机,是一个配置文件里面定义监控的主机;
(3)、各种模块核心模块、command模块、自定义模块;
(4)、借助于插件完成记录日志邮件等功能;
(5)、playbook:剧本执行多个任务时,非必需可以让节点一次性运行多个任务
2.ansible怎么用
2.1 命令结构
形式:ansible host_name [-i host] -m module_name
常用模块有:ping copy shell cron等等
ansible test -m copy -a 'src=/etc/issue dest=/tmp/issu.txt mode=600'
ansible test -m shell -a 'echo 111 > /tmp/test.txt'
2.2 ansible-playbook用法
- hosts: webservers #主机
vars: #变量
http_port: 80
max_clients: 200
remote_user: root #用户
tasks: #任务集合
- name: ensure apache is at the latest version #任务名字
yum: pkg=httpd state=latest #任务内容
- name: write the apache config file
template: src=/srv/httpd.j2 dest=/etc/httpd.conf
notify: #通知
- restart apache
- name: ensure apache is running
service: name=httpd state=started
handlers: #回调任务 被通知到,执行
- name: restart apache
service: name=httpd state=restarted
参考地址
http://www.ansible.com.cn/docs/playbooks_intro.html
2099

被折叠的 条评论
为什么被折叠?



