问题描述
---
- 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"
'' 错误: 致命:[本地主机]:失败! => {"msg": "条件检查 'item-app_extention not in applist.stdout_lines' 失败。错误是:意外的模板类型错误发生在 ({% if item-app_extention not in applist.stdout_lines %} 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_lines\n- name: Create xedge应用到生产 ns\n ^ 这里\n"}
''
解决方法
您正在尝试对字符串值执行减法运算,这里:
with_items:
- "{{production_apps}}"
#skip apps creation if apps are already existed
when : "item-app_extention not in applist.stdout_lines"
不带引号的变量名是变量引用。您尝试从 app_extention
中减去 item
。我想你的意思是这样的:
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