微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如果stdout结果等于失败,如何使用Ansible重新启动服务器?

如何解决如果stdout结果等于失败,如何使用Ansible重新启动服务器?

我为jboss编写任务,但是如果stdout结果等于失败,我不知道如何重新启动服务器。

我的任务

- name: Server
  become: true
  check_deployments: 
    server: 111.111.111.111:8888
    command: /deployment=*:read-attribute(name=status)
    cli_path: /testusers/wildfly/bin
    user: admin
    password: admin
  register: command

- name: wf_debug  
  debug:
    msg: "{{ command.stdout_lines}}"

输出

TASK [check_wf_status : wf_debug] ******************************************************************************************************************************************
ok: [111.111.111.111] => {
    "msg": [
        "{","    \"outcome\" => \"success\",","    \"result\" => [","        {","            \"address\" => [(\"deployment\" => \"test-module1\")],"            \"outcome\" => \"success\","            \"result\" => \"OK\"","        },"            \"address\" => [(\"deployment\" => \"test-module2\")],"            \"result\" => \"Failed\"","    ]","}"
    ]
}

如果result = Failed,如何使用Ansible重启服务器?

解决方法

如果result = FAILED,如何使用Ansible重启服务器?

这应该可以工作,就像to the docs

- name: Unconditionally reboot the machine with all defaults,when the check_deployments task has failed
  reboot:
  when: "'FAILED' in command.stdout_lines"

请注意,您正在注册“命令”。这也是一个不良的模块,可能引起混乱。最好用其他名称注册它,例如register: check_deploy

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。