1
votes
---
- 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"

'' error: fatal: [localhost]: FAILED! => {"msg": "The conditional check 'item-app_extention not in applist.stdout_lines' failed. The error was: Unexpected templating type error occurred on ({% if item-app_extention not in applist.stdout_lines %} True {% else %} False {% endif %}): unsupported operand type(s) for -: 'AnsibleUnsafeText' and 'AnsibleUnicode'\n\nThe error appears to be in '/etc/ansible/roles/xedge/tasks/argocd_apps.yml': line 8, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n var: applist.stdout_lines\n- name: Create xedge apps to production ns\n ^ here\n"}

''

1
Please some one help me in the above issue..Haridvpsk

1 Answers

1
votes

You're trying to perform substration on string values, here:

  with_items:
          - "{{production_apps}}"
 #skip apps creation if apps are already existed
  when : "item-app_extention not in applist.stdout_lines"

An unquoted variable name is a variable reference. You're try to subtract app_extention from item. I think you mean something like:

when: "item ~ '-' ~ app_extention not in applist.stdout_lines

Where ~ is the string concatenation operator.

Or with less confusing quoting, using the > folding block operator so we're not nesting quotes:

when: >
  item ~ '-' ~ app_extention not in applist.stdout_lines

Or using string formatting rather than concatenation:

when: >
  '%s-%s' % (item, app_extention) not in applist.stdout_lines