我想创建一个与此类似的程序流:
- name: Clone git repository
block:
- git:
repo: "{{ project_gitlab_repository }}"
dest: "{{ project_build_path }}"
async: 120
poll: 5
rescue:
- file:
path: "{{ project_build_path }}"
state: absent
- ansible.builtin.command: /bin/false
retries: 3
上面的代码不起作用,看来您可以重试块。 是否可以在Ansible中实现这样的目标?
答案 0 :(得分:0)
我通过将以下代码放入文件“ clone_git_repository.yaml”来解决了这个问题(hacky)
- block:
- name: Clone git repository
git:
repo: "{{ project_gitlab_repository }}"
dest: "{{ project_build_path }}"
async: 120
poll: 5
rescue:
- set_fact:
retry_count: "{{ 0 if retry_count is undefined else retry_count | int + 1 }}"
- fail:
msg: maximum retries reached
when: retry_count | int == 5
- command: "rm -rf {{ project_build_path }}"
- include_tasks: clone_git_repository.yml
不太优雅,但是显然可以这样,直到您可以为某个块指定重试。