---
- name: test
hosts: localhost
tasks:
- name: Checking project list
shell: |
argocd proj list | grep xcore
register: argoProj
- debug: var=argoProj.stdout
- name: create a project if not exits
shell: |
argocd proj create xcore
# when: argoProj.stdout != "xcore"
when: argoProj.stdout.find('xcore')!=-1错误:
''
TASK [create a project if not exits] *****************************************************************************************
fatal: [localhost]: FAILED! => {"changed": true, "cmd": "argocd proj create xcore\n \n# when: argoProj.stdout != \"xcore\"\n", "delta": "0:00:00.807940", "end": "2021-02-04 09:11:24.257123", "msg": "non-zero return code", "rc": 20, "start": "2021-02-04 09:11:23.449183", "stderr": "time=\"2021-02-04T09:11:24Z\" level=fatal msg=\"rpc error: code = InvalidArgument desc = existing project spec is different, use upsert flag to force update\"", "stderr_lines": ["time=\"2021-02-04T09:11:24Z\" level=fatal msg=\"rpc error: code = InvalidArgument desc = existing project spec is different, use upsert flag to force update\""], "stdout": "EE: 0/[]", "stdout_lines": ["EE: 0/[]"]}注意:当已经创建了xcore项目时,我想跳过最后一个任务。当没有同名的项目时,需要执行最后一个任务。
shell命令的实际输出:
#argocd proj list | grep xcore
xcore gke_ec2nf-256816_us-central1_gke-devops,production <none> <none> <none> <none> disabled发布于 2021-02-04 17:33:51
---
- name: test
hosts: localhost
tasks:
- name: Checking project list
shell: argocd proj list | grep xcore
register: argoProj
- debug: var=argoProj.stdout
- name: create a project if not exits
shell: argocd proj create xcore
when: "'xcore' not in argoProj.stdout"https://stackoverflow.com/questions/66042624
复制相似问题