ansible 剧本 - 重启领事模板失败

问题描述 投票:0回答:1

我有一个包含这段代码的 ansible 剧本:

- name: Start service
  systemd:
    daemon_reload: yes
    state: restarted
    name: "consul-template"

ansible 失败并出现此错误:

fatal: [unix://var/run/docker.sock]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "daemon_reexec": false,
            "daemon_reload": true,
            "enabled": null,
            "force": null,
            "masked": null,
            "name": "consul-template",
            "no_block": false,
            "scope": null,
            "state": "restarted",
            "user": null
        }
    },
    "msg": "Unable to restart service consul-template: Warning! D-Bus connection terminated.\nFailed to wait for response: Connection reset by peer\n"
}

因为我怀疑存在赛车问题,所以通过重试修复了代码。新代码:

- name: Start service
  system:
    daemon_reload: yes
    state: restarted
    name: "consul-template"
    register: consul_template_result
  until: consul_template_result is succeeded
  retries: 20
  delay: 10

但是现在我得到这个错误:

fatal: [unix://var/run/docker.sock]: FAILED! => {
    "msg": "The conditional check 'consul_template_result is succeeded' failed. The 
error was: The 'failed' test expects a dictionary"
}

我试过:

- name: Start service
  systemd:
    daemon_reload: yes
    state: restarted
    name: "consul-template"
    register: consul_template_result
  until: not consul_template_result.failed
  retries: 20
  delay: 10

但是我得到这个错误:

    fatal: [unix://var/run/docker.sock]: FAILED! => {
    "msg": "The conditional check 'not consul_template_result.failed' failed. The error was: error while evaluating conditional (not consul_template_result.failed): 'consul_template_result' is undefined"
}

如何解决?

谢谢

ansible consul-template
1个回答
0
投票

register 关键字的缩进错误。 register 关键字不是模块输入,因此您需要以相同的方式缩进重试。

- name: Start service
  systemd:
    daemon_reload: yes
    state: restarted
    name: "consul-template"
  register: consul_template_result
  until: not consul_template_result.failed
  retries: 20
  delay: 10

关于您最初关于 DBUS 连接的错误。您很可能在 docker 引擎中运行的 docker 容器中调用此任务?如果是这样,这是预料之中的,因为 docker 不支持 systemd。您可以使用支持 systemd 的 podman(https://podman.io/

© www.soinside.com 2019 - 2024. All rights reserved.