使用场景  

    Ansible 由于采用ssh远程连接登录管理,虽然不需要额外安装agent,但是速度慢效率低.不适合管理大规模的主机一般最大规模在200-300台,超大规模的主机管理适合使用puppet

模板

     templates功能:根据模块文件动态生成对应的配置文件 

     templates文件必须存放于templates目录下,且命名为 .j2 结尾 

     yaml/yml 文件需和templates目录平级 

 

Jinja2语言

     字符串:使用单引号或双引号

     数字:整数,浮点数

     列表:[item1, item2, ...]

     元组:(item1, item2, ...)

     字典:{key1:value1,     key2:value2, ...}

     布尔型:true/false 

     算术运算:+,   -,   *,   /,   //,    %,   **         // 表示把相除得到的结果取整数

     比较操作: ==,    !=,    >,    >=,   <,    <= 

     逻辑运算:and,    or,     not 

     流表达式: for      if     when

   when条件判断语法
  tasks:
    - name: install nginx
      yum: name=nginx
    - name: copy config for 6
      template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf
      when: ansible_distribution_major_version == "6"
      notify: restart nginx
    - name: copy config for 7
      template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf
      when: ansible_distribution_major_version == "7"
when条件判断

相关文章:

  • 2022-12-23
  • 2021-07-22
  • 2021-09-29
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
  • 2021-10-15
猜你喜欢
  • 2022-12-23
  • 2021-12-25
  • 2021-06-19
  • 2022-01-31
  • 2021-08-18
  • 2022-12-23
  • 2022-02-23
相关资源
相似解决方案