【问题标题】:Handling Jenkins status failure from exit code of Ansible plabook从 Ansible 剧本的退出代码处理 Jenkins 状态失败
【发布时间】:2023-01-12 22:37:31
【问题描述】:

希望使用 Ansible 在 Linux 上处理系统重启并将其作为剧本的一部分与其他问题一起运行。

看到退出代码为 4 & 由于 Jenkins 作业导致失败,尽管它已经重新启动了机器。

有没有办法通过从 Jenkins 调用 ansible playbook 或从 playbook 中调用来处理此失败。

除了普通的 reboot: 任务之外,甚至还尝试了类似下面的内容,但仍然没有运气。请建议处理此问题的替代方法。

- name: Reboot the machine
  shell: |
    shutdown -r now && exit 0 
  ...
  ....

错误如下

Reboot the machine ---------------------------------------- 1.02s
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 4
Finished: FAILURE

【问题讨论】:

标签: jenkins ansible jenkins-pipeline ansible-2.x shutdown


【解决方案1】:

根据给定的描述、任务和错误信息

ERROR: script returned exit code 4

Ansible 连接到的设备将比 Ansible 更快地重新启动,并且模块 shell 可以保持自己的连接。意思是,关闭并断开会话。

在您的示例中,错误本身意味着 Interrupted system call 甚至 Network Error

你可以试试

- name: Schedule reboot in 1 min
  shell:
    cmd: "shutdown -r +1"
  register: result

- name: Show result
  debug:
    var: result

或者更好reboot module – Reboot a machine

进一步阅读

关于过去用于 Linux 系统的方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多