致命:[本地主机]:失败! => {"changed": false, "msg": "服务处于未知状态", "status": {}}

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

这是我的 ansible 剧本,我只是在启动和启用 Grafana 的最终任务中遇到了问题。

---
- name: Install Grafana
  hosts: hosts
  become: yes

  tasks:
  - name: download apt key
    ansible.builtin.apt_key:
      url: https://packages.grafana.com/gpg.key
      state: present
  - name: Add Grafana repo to sources.list 
    ansible.builtin.apt_repository:
      repo: deb https://packages.grafana.com/oss/deb stable main
      filename: grafana
      state: present
  - name: Update apt cache and install Grafana
    ansible.builtin.apt:
      name: grafana
      update_cache: yes
  - name: Ensure Grafana is started and enabled
    ansible.builtin.systemd:
      name: grafana-server
      state: started
      enabled: yes

这是我收到的错误:

TASK [Ensure Grafana is started and enabled]
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Service is in unknown state", "status": {}}

这也是我的主机文件的配置,以防万一:

[hosts]
localhost
[hosts:vars]
ansible_connection=local
ansible_python_interpreter=/usr/bin/python3

我几乎只是想让它运行我在 bash 脚本中的这两个命令

sudo systemctl start grafana-server
sudo systemctl enable grafana-server.service
ansible grafana
1个回答
0
投票

解决了 - 结果我的系统没有使用 systemd 作为 init 系统启动。所以我将 Ansible 模块从

ansible.builtin.systemd
更改为
ansible.builtin.sysvinit

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