dyok 发表于 2018-7-29 07:28:26

ansible企业级自动化运维工具

  ansible工具远程执行批量操作:
  1、安装httpd包   2、复制httpd服务配置文件    3、启动或重启httpd服务
  

- 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使用模板
  templates功能:根据模块文件动态生成对应的配置文件
  templates文件必须存放于templates目录下,且命名为 .j2 结尾
  yaml/yml 文件需和templates目录平级,目录结构如下:
  ./
  ├── temnginx.yml
  └── templates
  └── nginx.conf.j2

  tmpnginx.yml(变量优先级由高到低:命令行-à playbook—) 主机清单)


  ../templates/nginx.conf配置文件做如下参数修改
  按照cpu的个数生成进程数量


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

  groups指定用户的辅助组迭代调用

  hping3控制ping的速度

  迭代嵌套子变量迭代嵌套子变量
页: [1]
查看完整版本: ansible企业级自动化运维工具