Skip Ansible task when variable not defined

前端 未结 1 666
醉酒成梦
醉酒成梦 2021-01-15 02:11

I have the following task in a playbook:

- name: task xyz  
  copy:  
    src=\"{{ item }}\"  
    dest=\"/tmp/{{ item }}\"  
  with_items: \"{{ y.z }}\"  
          


        
1条回答
  •  温柔的废话
    2021-01-15 02:42

    The problem here is that with_items is evaluated before when. Actually in real scenarios you put item in the when conditional. See: Loops and Conditionals.

    This task will work for you:

    - name: task xyz
      copy:  
        src: "{{ item }}"  
        dest: "/tmp/{{ item }}"  
      with_items: "{{ (y|default([])).z | default([]) }}"
    

    0 讨论(0)
提交回复
热议问题