Ansible 可解析条件查找

Ansible 可解析条件查找,ansible,Ansible,我有一个剧本,其中的任务如下所示。push_config和import_consul都未传递,因此默认情况下为false - name: checkout config-tibco repository git: repo: ssh://git@bitbucket.corp.contingo.com:7999/gwa/config-tibco.git dest: "/opt/awx/tmp/config-tibco/" when: "{

我有一个剧本,其中的任务如下所示。push_config和import_consul都未传递,因此默认情况下为false

  - name: checkout config-tibco repository
      git:
        repo: ssh://git@bitbucket.corp.contingo.com:7999/gwa/config-tibco.git
        dest: "/opt/awx/tmp/config-tibco/"
      when: "{{ push_config | default(false) | bool }} or {{ import_consul | default(false) | bool }}"
...
....
.....

 - name: Update Consul KV Store
   shell: curl --request PUT -d "{{item.split('=',1) [1]}}" "http://{{ consul_host }}:{{ consul_port }}/v1/kv//TEST/{{ bw_application_name.stdout }}/{{ app_profile }}/{{item.split('=',1) [0]}}"
   loop: "{{ lookup('file', '/opt/awx/tmp/config-tibco/properties/*.properties').splitlines() }}"
   when: "{{ import_consul | default(false) | bool }}"
我希望第二个任务-updateconsukv Store应该被忽略,因为条件应该是false。第二个任务中预期的查找文件将仅在条件为真时(即import_Consor)下载/签出,因此它将在第一个任务中从GIT签出,并可用于第二个任务

但我得到以下关于查找文件的异常。这里的问题是,当条件已经设置为false时,为什么它还要尝试评估任务模块

fatal: [host machine]: FAILED! => {"msg": "An unhandled exception occurred while running the lookup plugin 'file'. Error was a <class 'ansible.errors.AnsibleError'>, original message: could not locate file in lookup: /opt/awx/tmp/config-tibco/properties/*.properties"}
有什么建议吗

Q:原始消息:在查找中找不到文件:/opt/awx/tmp/config tibco/properties/*.properties

答:在每次迭代中都必须计算when条件,因为条件可能取决于项。因此,必须在开始之前对循环进行评估

注释

该插件不能使用通配符。改用

为避免错误,请检查文件是否存在,如果文件不存在,请终止播放

始终至少创建空文件default.properties

当第一个和第二个条件都出现时,将导致警告

[警告]:条件语句不应包含jinja2模板分隔符,如{{}或{%}。发现:{{ 导入领事| defaultfalse | bool}

先修一修,同上

when: import_consul|default(false)|bool