qq591577286 发表于 2018-7-31 06:11:15

ansible(七)Conditionals 和 loops,自定义loops插件

---  
- hosts: salt-master
  
tasks:
  
    - name: with_items,参数为列表,列表元素为字符串或字典
  
      debug: msg='`item`.`name` and `item`.`age`'
  
      with_items:
  
      - {name: 'lixc',age: 25}
  
      - {name: 'liss',age: 24}
  
      when: 1
  

  
    - name: with_nested,打印嵌套列表,参数为列表,列表元素为列表
  
      debug: msg='{{item}} and {{item}}'
  
      with_nested:
  
      - ['lixc','liss']
  
      -
  
      when: ansible_os_family == "Debian"
  

  
    - name: with_dict,循环字典,参数为字典
  
      debug: msg='`item`.`key` and `item`.`value`'
  
      with_dict:
  
      ansible:
  
          cmd: commandline
  
          ply: playbooks
  
      salt:
  
          cmd: commandline
  
          st: state
  
      when: ansible_os_family == "Debian" and "8"|int >= 6
  

  
    - name: with_fileglob,遍历文件夹下的文件,不包括文件夹,roles可为相对路径
  
      debug: msg=`item`
  
      with_fileglob:
  
      - /tmp/test1/*
  
      - /tmp/test2/*
  
      when: lixc is not defined
  

  
    - name: with_sequence,获得整数序列
  
      debug: msg=`item`
  
      with_sequence: start=4 end=8 stride=2
  
      when: 1 in
页: [1]
查看完整版本: ansible(七)Conditionals 和 loops,自定义loops插件