ansible

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

     

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值