0

Running a CentOS 8 Stream server with nfs-utils version 2.3.3-57.el8 and using ansible-playbook core version 2.11.12 with a test 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

will render the following results

service_facts

...
"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",
...

The NFS Server is very much running/active but the service_facts fails to report it as such.

Other services, such as httpd reports correct state in service_facts.

Have I misunderstood or done something wrong here? Or have I run in to an anomaly?

Enok82
  • 1
  • Did you've got the chance to do further testing according [stackoverflow question and answer](https://stackoverflow.com/a/73958274/6771046)? If so, what are the test results? – U880D Oct 10 '22 at 07:16
  • I did take a look for the duplicate files you mentioned but they were not present in my system. – Enok82 Oct 10 '22 at 07:33
  • It also shows a process of how to test, which results are interesting and how to provide the test results. [ansible/modules/service_facts.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/service_facts.py#L220) seems to try and use different approaches of how to gather the actual status of services. This difference in reporting seems to come from that part. – U880D Oct 10 '22 at 07:42
  • After further investigation regarding Ansible Issue #[67262](https://github.com/ansible/ansible/issues/67262) "_`service_facts` does not return correct state for services_", it might be that this is somehow caused by [What does status "`active (exited)`" mean for a systemd service?](https://unix.stackexchange.com/questions/241970/) and [`def _list_rh(self, services)`](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/service_facts.py#L147) and even if already set `RemainAfterExit=yes` within the `.service` files. Because the service seems not to be `running` but `exited`. – U880D Oct 20 '22 at 09:43
  • ... I've provided an update with more investigation under [`nfs-server` state in `service_facts` differ from `ansible.builtin.systemd`](https://stackoverflow.com/a/73958274/6771046). – U880D Oct 21 '22 at 08:56

0 Answers0