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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在Ansible劇本的with_items循環(huán)中注冊變量

在Ansible劇本的with_items循環(huán)中注冊變量

GCT1015 2019-11-19 15:10:03
我有一個不同名稱的字典,例如vars:    images:      - foo      - bar不,我想簽出存儲庫,然后僅在源發(fā)生更改時才構(gòu)建docker映像。由于獲取源代碼和構(gòu)建圖像對于所有項(xiàng)目都是相同的,除了我創(chuàng)建任務(wù)的名稱,with_items: images 并嘗試將結(jié)果注冊到:register: "{{ item }}"并嘗試了register: "src_{{ item }}"然后我嘗試了以下條件when: "{{ item }}|changed"和when: "{{ src_item }}|changed"這總是導(dǎo)致 fatal: [piggy] => |changed expects a dictionary那么,如何根據(jù)我遍歷的列表將操作結(jié)果正確保存在變量名稱中?更新:我希望有這樣的東西:- hosts: all  vars:    images:      - foo      - bar  tasks:    - name: get src      git:        repo: git@foobar.com/repo.git        dest: /tmp/repo      register: "{{ item }}_src"      with_items: images    - name: build image      shell: "docker build -t repo ."      args:        chdir: /tmp/repo      when: "{{ item }}_src"|changed      register: "{{ item }}_image"      with_items: images    - name: push image      shell: "docker push repo"      when: "{{ item }}_image"|changed      with_items: images
查看完整描述

1 回答

?
慕尼黑5688855

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超2個贊

那么,如何根據(jù)我遍歷的列表將操作結(jié)果正確保存在變量名稱中?


不用了 為with_items具有不同格式的任務(wù)注冊的變量,它們包含所有項(xiàng)目的結(jié)果。


- hosts: localhost

  gather_facts: no

  vars:

    images:

      - foo

      - bar

  tasks:

    - shell: "echo result-{{item}}"

      register: "r"

      with_items: "{{ images }}"


    - debug: var=r


    - debug: msg="item.item={{item.item}}, item.stdout={{item.stdout}}, item.changed={{item.changed}}"

      with_items: "{{r.results}}"


    - debug: msg="Gets printed only if this item changed - {{item}}"

      when: item.changed == true

      with_items: "{{r.results}}"


查看完整回答
反對 回復(fù) 2019-11-19
  • 1 回答
  • 0 關(guān)注
  • 800 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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