第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

Ansible Loops

一、简介    

通常一个任务会做很多事情,如创建大量的用户,安装很多包,或重复的轮询特定的步骤,直到某种结果条件为止,Ansible为我们提供了此支持。下面是关于循环的一些语句。


with_items     #标准循环

with_nested    #嵌套循环

with_dict          #字典循环(Looping over hashed)

with_file       #循环文件

with_fileglob    #通配符循环文件

with_together    #循环映射

with_subelements  #子元素循环

with_sequence      #生成一系列的数字

with_random_choice   #任意选择

#with_first_found      #选择第一个找到的,不会用

with_lines          #循环程序执行的输出信息with_items:`command_result`.`stdout_lines`

with_flattened      #循环列表中的列表的item


二、实例

---
- hosts: local                        #with_item 和 with_nested 用法
  vars:
    Sta: false
    User: [ "Aheahe","yunzhonghe" ]
  tasks:
  - name: Standard Loops
    debug: msg="{{ item.name }},{{ item.fun }}"
    with_items:                  #生成标准循环
     - { name: Loops, fun: xx }
     - { name: Conditional, fun: yy }
    when: Sta
  - name: Nested Loops
    debug: msg= "name={{ item[0] }},priv={{ item[1] }}"
    with_nested:                  #嵌套循环
     - "{{ User }}"                #这里的User 可以直接使用列表。
     - [ "Student","Engineer","Friends" ]


---
- hosts: local          #with_dict 用法
#  vars_files:
#    hash.yml
  vars:
    users:
      alice:
        name: Alice Appleworth
        telephone: 123-456-7890
      bob:
        name: Bob Bananarama
        telephone: 987-654-3210
  tasks:
  - name: Print phone records
    debug: msg="User  item.key  is  item.value.name   item.value.telephone "
    with_dict: users              #循环列表可以查看输出信息。以获取结果


---
- hosts: local                 #with_file 与 with_fileglob 用法。
  vars:
    test_file: false
  tasks:
  - name: test file
    shell: echo {{ item }}
    with_file:         #循环文件的内容
     - test                          #test文件里面为任意内容。
     - test1
    when: test_file
 
  - name: Test file Glob
    shell: echo {{ item }}
    with_fileglob:     #循环文件的通配符。
    - /home/aheahe/playbook/*


---
- hosts: local                 #with_together用法
  vars:
    alpha: [ 'a', 'b', 'c', 'd' ]
    numbers:  [ 1, 2, 3, 4 ]
    test: [ 'A', 'B', 'C', 'D' ]
  tasks:
   - debug: msg="{{ item.0 }} and {{ item.1 }} and {{ item.2 }}"
     with_together:                #循环映射信息
       - "`alpha`"
       - "`numbers`"
       - "`test`"


---
- hosts: local         #with_subelement用法
  vars:
    users:
      - name: alice
        authorized:
          - /tmp/alice/onekey.pub
          - /tmp/alice/twokey.pub
        mysql:
            password: mysql-password
            hosts:
              - "%"
              - "127.0.0.1"
              - "::1"
              - "localhost"
            privs:
              - "*.*:SELECT"
              - "DB1.*:ALL"
      - name: bob
        authorized:
          - /tmp/bob/id_rsa.pub
        mysql:
            password: other-mysql-password
            hosts:
              - "db1"
            privs:
              - "*.*:SELECT"
              - "DB2.*:ALL"
  tasks:
  - name: Test1
    shell: echo "name={{ item.name }}"
    with_items: "`users`"
  - name: Test2
    shell: echo "User={{ item.0.name }},key={{ item.1 }}"
    with_subelements:         #循环子元素。
    - users
    - authorized


---
- hosts: local
  tasks:
  - name: Learn loop sequence
    debug: msg={{ item }}
    with_sequence: start=0 end=6 stride=2


---
- hosts: local                 # with_random_choice 用法
  tasks:
  - name: Learn Random
    debug: msg={{ item }}
    with_random_choice:
     - "go through the door"
     - "drink from the goblet"
     - "press the red button"
     - "do nothing"


---
- hosts: local         #with_lines 用法
  tasks:
  - name: test result
    shell: echo {{ item }}
    with_lines: /bin/df -Th
 
- name: flattened loop demo                       #with_flatted用法
  yum: name={{ item }} state=installed
  with_flattened:
     - "`packages_base`"
     - "`packages_apps`"
----
# file: roles/foo/vars/main.yml
packages_base:
  - [ 'foo-package', 'bar-package' ]
packages_apps:
  - [ ['one-package', 'two-package' ]]
  - [ ['red-package'], ['blue-package']]



點擊查看更多內(nèi)容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
JAVA開發(fā)工程師
手記
粉絲
1.1萬
獲贊與收藏
1545

關(guān)注作者,訂閱最新文章

閱讀免費教程

  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優(yōu)惠券免費領(lǐng)

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消