ansible企业级自动化运维工具

ansible工具远程执行批量操做:
一、安装httpd包 二、复制httpd服务配置文件 三、启动或重启httpd服务nginx

- hosts: web
  remote_user: root

  tasks:
    - name: install httpd
      yum: name=httpd
    - name: copy file
      copy: src=/etc/httpd/conf/httpd.conf dest=/etc/httpd/conf/ backup=yes
      tags: copyconf
      notify: restart httpd
    - name: start httpd
      service: name=httpd state=started enabled=yes

  handlers:
    - name: restart httpd
      service: name=httpd state=restarted

 ansible使用模板web

templates功能:根据模块文件动态生成对应的配置文件
templates文件必须存放于templates目录下,且命名为 .j2 结尾
yaml/yml 文件需和templates目录平级,目录结构以下:
./
├── temnginx.yml
└── templates
└── nginx.conf.j2
 
 
 运维

 ansible企业级自动化运维工具
 
tmpnginx.yml(变量优先级由高到低:命令行-à playbook—) 主机清单)ide

ansible企业级自动化运维工具
 

 ansible企业级自动化运维工具
../templates/nginx.conf配置文件作以下参数修改
按照cpu的个数生成进程数量
ansible企业级自动化运维工具
 
 
ansible企业级自动化运维工具工具

 
 
 
若是须要根据变量、facts或此前任务的执行结果来作为某task执行与否的前提时要用到条件测试,经过when语句实现测试

 ansible企业级自动化运维工具
 
groups指定用户的辅助组 迭代调用命令行

 
 ansible企业级自动化运维工具
 
 
hping3控制ping的速度3d

 ansible企业级自动化运维工具
 
迭代嵌套子变量迭代嵌套子变量rest

ansible企业级自动化运维工具

相关文章
相关标签/搜索