doina

一个小菜鸟运维工程师.

Ansible 忽略错误继续执行

正常情况下 ansible执行时碰到错误就停止执行了
想要让他继续执行可以使用 ignore_errors: yes 参数来保证继续执行

未修改前

# playbook
  - name: install java
    win_package:
      path: c:\\tools\\jdk-7u2-windows-x64.exe
      product_id: jdk-7u2
      arguments:
        - /s
        - /quiet
      state: present

#执行过程(到这里就停止了)
TASK [install java] ******************************************************************************
*********************************
fatal: [10.241.0.4]: FAILED! => {"changed": false, "exit_code": 1603, "msg": "unexpected rc from
install  c:\\\\tools\\\\jdk-7u2-windows-x64.exe: see rc, stdout and stderr for more details", "rc"
: 1603, "reboot_required": false, "restart_required": false, "stderr": "", "stderr_lines": [],
"stdout": "", "stdout_lines": []}
        to retry, use: --limit @/data/Ansible-playbook/winchannel/win_soft/win_soft.retry

PLAY RECAP ***************************************************************************************
*********************************
10.241.0.4                 : ok=1    changed=0    unreachable=0    failed=1   


修改后

# playbook
  - name: install java
    win_package:
      path: c:\\tools\\jdk-7u2-windows-x64.exe
      product_id: jdk-7u2
      arguments:
        - /s
        - /quiet
      state: present
    ignore_errors: yes  #新增

# 再次执行
TASK [install java] ******************************************************************************
****************************************************************************************
fatal: [10.241.0.4]: FAILED! => {"changed": false, "exit_code": 1603, "msg": "unexpected rc from
install  c:\\\\tools\\\\jdk-7u2-windows-x64.exe: see rc, stdout and stderr for more details", "rc"
: 1603, "reboot_required": false, "restart_required": false, "stderr": "", "stderr_lines": [],
"stdout": "", "stdout_lines": []}
...ignoring #忽略报错

TASK [install 7-Zip] *****************************************************************************
****************************************************************************************
changed: [10.241.0.4]

TASK [unzip *.7z] ********************************************************************************
****************************************************************************************
changed: [10.241.0.4] => (item=BGInfo.zip)
changed: [10.241.0.4] => (item=cygwin64.zip)
changed: [10.241.0.4] => (item=autoStart.zip)
changed: [10.241.0.4] => (item=rsync_server_winc.zip)

TASK [Add JAVA_HOME Env] *************************************************************************
****************************************************************************************
ok: [10.241.0.4]

TASK [Add cygwin Env] ****************************************************************************
****************************************************************************************
ok: [10.241.0.4] => (item=C:\tools\cygwin64)
ok: [10.241.0.4] => (item=C:\Program Files\7-Zip)
ok: [10.241.0.4] => (item=C:\Program Files\Java\jdk1.7.0_02\bin)

PLAY RECAP ***************************************************************************************
****************************************************************************************
10.241.0.4                 : ok=6    changed=2    unreachable=0    failed=0   
点赞

发表评论

邮箱地址不会被公开。

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据