我有以下变量:
secureVar:
cosmosconstr: ""
postgresUrl: ""
它可以为空或包含数据库 url,具体取决于我需要在 kubernetes 中有条件地创建外部服务:
- name: Get DB data
when: (secureVars | from_json)['cosmosconstr'] | length == 0 and (secureVars | from_json)['postgresUrl'] | length == 0
shell: ./python/db_credentials.py -dp {{ deploymentPrefix }}
register: dbData
- name: Generate external services templates
when: (secureVars | from_json)['cosmosconstr'] | length == 0 and (secureVars | from_json)['postgresUrl'] | length == 0
action: template src=k8s/common/external-services.j2 dest=/tmp/k8s-external-svc.yml
vars:
cosmosUrl: "{{ dbData.stdout_lines[0] | urlsplit('hostname') }}"
postgresUrl: "{{ dbData.stdout_lines[1] }}"
- name: Generate external services templates
when: (secureVars | from_json)['cosmosconstr'] | length > 0 and (secureVars | from_json)['postgresUrl'] | length > 0
action: template src=k8s/common/external-services.j2 dest=/tmp/k8s-external-svc.yml
vars:
cosmosUrl: "{{ ( secureVars | from_json )['cosmosconstr'] | urlsplit('hostname') }}"
postgresUrl: "{{ ( secureVars | from_json )['postgresUrl'] }}"
这就是我现在正在做的事情,我想设置一个条件,以便如果跳过 dbData 我会使用secureVars,如果没有跳过我会使用 dbData,问题是,我无法检查是否dbData.skipped等于 true,因为如果它没有被跳过,它不包含skipped属性
守着一只汪
相关分类