【问题标题】:Fail task/play when host not reachable Ansible当主机无法访问 Ansible 时任务/播放失败
【发布时间】:2019-06-22 05:34:53
【问题描述】:

我编写了一个剧本,它将文件从多个主机上的源复制到目标。如果所有主机都可以访问,则 playbook 可以工作,但如果其中一个主机无法访问,它不会失败。

ansible-playbook -i "10.11.12.13,10.11.12.14," -e "hostid=12345" test.yml

。如果主机“10.11.12.13”不可访问,任务执行会跳过不可访问的主机并移动到下一个主机。

示例手册

- hosts: localhost
  gather_facts: no
  tasks:
    - debug: msg="backup_restore.py file not found"


- name: Copy file
  hosts: all
  remote_user: test
  gather_facts: no
  vars:
    srcFolder: "/home/test"
    destFolder: "/opt/config"
  tasks:
    - block:
        - name: Copy file to node
          copy:
            src:  '{{srcFolder}}/self.config'
            dest: '{{destFolder}}/self.config'

如果无法访问任何主机,是否有办法使任务失败。我正在使用 ansible 2.6.1。提前谢谢你。

【问题讨论】:

    标签: ansible


    【解决方案1】:

    蛮力解决方案是any_errors_fatal

    - name: Copy file
      hosts: all
      any_errors_fatal: true
    

    其他选项的概述在Abort execution of remaining task if certain condition is failed

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-13
      • 2021-12-27
      • 1970-01-01
      • 2018-06-07
      • 1970-01-01
      • 2017-05-18
      • 2017-02-23
      • 2016-10-09
      相关资源
      最近更新 更多