我使用寄存器变量来存储任务的输出值,所以我';m在ansible角色的when条件中使用相同的值
'' 错误: 致命:[localhost]:失败!=>{“msg”:“条件检查'item-app_扩展不在applist.stdout_行'失败。错误是:{%if item-app_扩展不在applist.stdout_行%}True{%else%}False{%endif%}上发生意外的模板类型错误:不支持的操作数类型对于-:“AnsibleUnsafeText”和“AnsibleUnicode”\n\n错误出现在“/etc/ansible/roles/xedge/tasks/argocd_apps.yml”:第8行第3列,但可能\n在文件的其他位置,具体取决于语法问题。\n\n有问题的行可能是:\n\n var:applist.stdout\n-lines\n-name:Create xedge apps to production ns\n^here\n”}我使用寄存器变量来存储任务的输出值,所以我';m在ansible角色的when条件中使用相同的值,ansible,ansible-role,Ansible,Ansible Role,'' 错误: 致命:[localhost]:失败!=>{“msg”:“条件检查'item-app_扩展不在applist.stdout_行'失败。错误是:{%if item-app_扩展不在applist.stdout_行%}True{%else%}False{%endif%}上发生意外的模板类型错误:不支持的操作数类型对于-:“AnsibleUnsafeText”和“AnsibleUnicode”\n\n错误出现在“/etc/ansible/roles/xedge/tasks/argocd_a
''您正在尝试对字符串值执行substation,如下所示:
---
- name: Check the apps list in ArgoCD server with related to cluster:"{{clustername.stdout}}"
shell: |
argocd app list | grep {{clusterip.stdout}} | grep {{proj_name}} | awk '{print $1}'
register: applist
- debug:
var: applist.stdout_lines
- name: Create xedge apps to production ns
shell: |
argocd app create {{item}}-{{app_extention}} --project {{proj_name}} --repo {{gitops_url}} --revision HEAD --values {{values_file}}.yaml --path {{item}} --dest-namespace production --label app={{item}} --dest-server {{clusterip.stdout}}
with_items:
- "{{production_apps}}"
#skip apps creation if apps are already existed
when : "item-app_extention not in applist.stdout_lines"
不带引号的变量名是变量引用。您正在尝试从项
中减去应用扩展
。我想你的意思是:
with_items:
- "{{production_apps}}"
#skip apps creation if apps are already existed
when : "item-app_extention not in applist.stdout_lines"
其中,~
是字符串连接运算符
或者,使用>
折叠块运算符,以减少混淆的报价,这样我们就不会嵌套报价:
when: "item ~ '-' ~ app_extention not in applist.stdout_lines
或使用字符串格式而不是串联:
when: >
item ~ '-' ~ app_extention not in applist.stdout_lines
请有人帮我解决上面的问题谢谢拉尔克斯先生。我正在检查上面的价值观查看您提供的所有价值观。非常感谢!!拉尔克斯先生。
when: >
'%s-%s' % (item, app_extention) not in applist.stdout_lines