如何让ansible使用服务而不是systemctl?

Zha*_* Yi 9 ansible

我正在使用 ansible 服务模块来重新启动系统服务。下面是ansible文件的配置。当我运行 ansible 命令时,出现与 systemctl 相关的错误。由于我的服务配置为使用 service 命令而不是 systemctl 运行,因此我希望 ansible 使用 service 命令来启动我的服务。有没有办法为此配置ansible?

- name: start cooltoo_storage service
sudo: yes
service:
  name: cooltoo_storage
  state: started
Run Code Online (Sandbox Code Playgroud)

运行 systemctl 时出现以下错误。而且我不想将我的服务配置为使用 systemctl 运行。

Job for cooltoo_storage.service failed because the control process exited with error code. See "systemctl status cooltoo_storage.service" and "journalctl -xe" for details.
Run Code Online (Sandbox Code Playgroud)

ree*_*gnz 5

这是ansible 2.2,所以上面应该可以工作:

- name: start cooltoo_storage service
  sudo: yes
  service:
    name: cooltoo_storage
    state: started
    use: service
Run Code Online (Sandbox Code Playgroud)

基本上,'use' 的默认值是 auto,它使用系统默认的服务管理器接口(例如 systemctl)。例如,当您确定系统具有“服务”命令时,您可以覆盖它。

详细信息可在文档中找到:https : //docs.ansible.com/ansible/latest/service_module.html

  • 这样对吗?`service` 模块似乎忽略了 `use` 选项。https://github.com/ansible/ansible/issues/37590 (3认同)