运行版本 2.3.3-57.el8 的 CentOS 8 Stream 服务器nfs-utils
并使用ansible-playbook
核心版本 2.11.12 和测试 playbook
- hosts: server-1
tasks:
- name: Collect status
service_facts:
register: services_state
- name: Print service_facts
debug:
var: services_state
- name: Collect systemd status
ansible.builtin.systemd:
name: "nfs-server"
register: sysd_service_state
- name: Print systemd state
debug:
var: sysd_service_state
将呈现以下结果
服务事实
...
"nfs-server.service": {
"name": "nfs-server.service",
"source": "systemd",
"state": "stopped",
"status": "disabled"
},
...
ansible.builtin.systemd
...
"name": "nfs-server",
"status": {
"ActiveEnterTimestamp": "Tue 2022-10-04 10:03:17 UTC",
"ActiveEnterTimestampMonotonic": "7550614760",
"ActiveExitTimestamp": "Tue 2022-10-04 09:05:43 UTC",
"ActiveExitTimestampMonotonic": "4096596618",
"ActiveState": "active",
...
NFS 服务器正在运行/活动,但service_facts
无法报告它。
其他服务,例如httpd
报告正确的状态service_facts
。
我在这里误解或做错了什么吗?或者我遇到了异常情况?