失败时重试ansible ad-hoc

时间:2019-03-05 03:56:06

标签: ansible ansible-ad-hoc

在ansible剧本中,我们可以检测到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"

0 个答案:

没有答案