zoukankan      html  css  js  c++  java
  • playbook变量(八)循环迭代

    1、基本使用

    [root@linux-node1 ansible]# cat testitem.yaml 
    ---
    - hosts: date
      remote_user: root
    
      tasks:
        - name: create some files
          file: name=/data1/{{ item }} state=touch
          with_items:
            - file1
            - file2
            - file3
        - name: install some packages
          yum: name={{ item }}
          with_items:
            - htop
            - sl
            - hping3
    

     2创建多个用户组

    [root@linux-node1 ansible]# cat testitem1.yaml
    ---
    - hosts: date
      remote_user: root
    
      tasks:
        - name: create some groups
          group: name={{ item }}
          when: ansible_distribution_major_version == "7"
          with_items:
            - g1
            - g2
            - g3
    

     

     2.1、嵌套自变量(指定用户组)

    [root@linux-node1 ansible]# cat testitem2.yaml
    ---
    - hosts: date
      remote_user: root
    
      tasks:
        - name: create some groups
          group: name={{ item }}
          when: ansible_distribution_major_version == "7"
          with_items:
            - g1
            - g2
            - g3
        - name: create some users
          when: ansible_distribution_major_version == "7"
          user: name={{ item.name }} group={{ item.group }}
          with_items:
            - { name: 'user1', group: 'g1' }
            - { name: 'user2', group: 'g2' }
            - { name: 'user3', group: 'g3' }
    

     

     

  • 相关阅读:
    POJ1417 True Liars
    POJ2912 Rochambeau
    POJ3904 Sky Code
    [SDOI2016]排列计数
    POJ2947 Widget Factory
    HDU5015 233 Matrix
    Problem 2242. -- [SDOI2011]计算器
    POJ2480 Longge's problem
    Problem 2818. -- Gcd
    LA3510 Pixel Shuffle
  • 原文地址:https://www.cnblogs.com/zhaojingyu/p/12133028.html
Copyright © 2011-2022 走看看