首页 > 解决方案 > 失败时重试 ansible ad-hoc

问题描述

在ansible playbook中,我们可以检测shell命令的结果,检查然后重试,如果有这样的失败

---
# Retry when failure
- hosts: all
  become: yes
  become_user: www-data
  vars:
    ansible_python_interpreter: /usr/bin/python3
  tasks:

  - name: checking test task
    shell: bin/console ahihi
    args:
      chdir: /var/www/backend/current/
      executable: /bin/bash
    register: result
    until: result == 0
    retries: 3
    delay: 15

但是如何在 ansible ad-hoc 命令中配置注册/直到/重试/延迟?因为我需要运行一个小命令(但有时会在网络问题或类似情况下失败),需要重试至少 3 次才能放弃。

这是我的临时命令:

ansible -i cron -m shell \
                --become --become-user www-data \
                -a "/var/www/backend/current/bin/console ahihi"

标签: ansibleansible-ad-hoc

解决方案


推荐阅读