ansible步骤失败时如何关闭主机
我有一个ansible任务,它正在运行“shell”模块。我已将任务设置为重试x次。如果在x次重试后shell命令仍然无法成功完成,我将如何使ansible关闭主机 下面是一个具有重试功能的shell命令示例:ansible步骤失败时如何关闭主机,ansible,Ansible,我有一个ansible任务,它正在运行“shell”模块。我已将任务设置为重试x次。如果在x次重试后shell命令仍然无法成功完成,我将如何使ansible关闭主机 下面是一个具有重试功能的shell命令示例: - name: Check if services are starting shell: | isStarting=$(ps -ef | grep -c mysoftware) if ((isStarting <= 0)) then su
- name: Check if services are starting
shell: |
isStarting=$(ps -ef | grep -c mysoftware)
if ((isStarting <= 0))
then
sudo systemctl start mysoftware
exit 1
else
exit 0
fi
retries: 5
delay: 10
register: result
until: result.rc == 0
ignore_errors: true
-名称:检查服务是否正在启动
外壳:|
IsStart=$(ps-ef | grep-c mysoftware)
如果((isStarting使用带有错误处理功能的a应该可以完成此任务。注意:我想当然地认为当前任务正在完成您期望的任务。请注意,我删除了忽略\u error
,因为我们想在这种情况下触发救援任务
- block
- name: Check if services are starting
shell: |
isStarting=$(ps -ef | grep -c mysoftware)
if ((isStarting <= 0))
then
sudo systemctl start mysoftware
exit 1
else
exit 0
fi
retries: 5
delay: 10
register: result
until: result.rc == 0
rescue:
- name: shutdown server
shell: shutdown -H now
- fail:
msg: "Services did not start, server was stopped"
-块
-名称:检查服务是否正在启动
外壳:|
IsStart=$(ps-ef | grep-c mysoftware)
如果((i)开始