ansible service_facts failed to find any services

Viewed 25
  tasks:
  - name: Gather the package facts
    ansible.builtin.package_facts:
      manager: auto

  - name: collect facts about system services
    ansible.builtin.service_facts:
    register: services_state

  - name: print system services
    ansible.builtin.debug:
      var: ansible_facts.services
    when: debug_services

  - name: print system services other option
    ansible.builtin.debug:
      var: services_state
    when: debug_services

-------------------------------------end of playbook------------------

--------output ----------------------------------------------------------------------

TASK [print system services] ***************************************************
ok: [instance_centos79] => {
    "ansible_facts.services": "VARIABLE IS NOT DEFINED!"
}
ok: [instance_centos8] => {
    "ansible_facts.services": "VARIABLE IS NOT DEFINED!"
}
ok: [instance_debian] => {
    "ansible_facts.services": {
        "apache-htcacheclean": {
            "name": "apache-htcacheclean",
            "source": "sysv",
            "state": "stopped"
        },
        "apache2": {
            "name": "apache2",
            "source": "sysv",
            "state": "stopped"
        },
        "procps": {
            "name": "procps",
            "source": "sysv",
            "state": "stopped"
        },
        "sudo": {
            "name": "sudo",
            "source": "sysv",
            "state": "stopped"
        }
    }
}

TASK [print system services other option] **************************************
ok: [instance_centos79] => {
    "services_state": {
        "changed": false,
        "failed": false,
        "msg": "Failed to find any services. This can be due to privileges or some other configuration issue.",
        "skipped": true
    }
}
ok: [instance_centos8] => {
    "services_state": {
        "changed": false,
        "failed": false,
        "msg": "Failed to find any services. This can be due to privileges or some other configuration issue.",
        "skipped": true
    }
}
ok: [instance_debian] => {
    "services_state": {
        "ansible_facts": {
            "services": {
                "apache-htcacheclean": {
                    "name": "apache-htcacheclean",
                    "source": "sysv",
                    "state": "stopped"
                },
                "apache2": {
                    "name": "apache2",
                    "source": "sysv",
                    "state": "stopped"
                },
                "procps": {
                    "name": "procps",
                    "source": "sysv",
                    "state": "stopped"
                },
                "sudo": {
                    "name": "sudo",
                    "source": "sysv",
                    "state": "stopped"
                }
            }
        },
        "changed": false,
        "failed": false
    }
}


-------for this playbook (im using molecule for this) i am getting the errors

----so it works for debianOS but not for CentOS ...any suggestions? where can the trick can be? i also tried become and it was not better....i tried googling but didnt find an answer. ........ so it works for debianOS but not for CentOS ...any suggestions? where can the trick can be? i also tried become and it was not better....i tried googling but didnt find an answer so it works for debianOS but not for CentOS ...any suggestions? where can the trick can be? i also tried become and it was not better....i tried googling but didnt find an answer

thanks ---------

0 Answers
Related