geerlingguy / docker-ubuntu2004-ansible

Ubuntu 20.04 LTS (Focal Fossa) Docker container for Ansible playbook and role testing.
https://hub.docker.com/r/geerlingguy/docker-ubuntu2004-ansible
MIT License
83 stars 49 forks source link

Service is in unknown state #16

Closed p3l1 closed 3 years ago

p3l1 commented 3 years ago

Hey there,

I am quite new to Molecule and currently developing an Ansible Role to install Zabbix Agent on Ubuntu, Debian and CentOS. After installation i want to ensure the service is up and running with the following task:

- name: Start Zabbix Agent service
  service:
    name: zabbix-agent
    state: started
  when:
    - ansible_os_family == 'RedHat' or
      ansible_os_family == 'Debian'

When running molecule converge the step fails for all three docker images and i can't figure out why.

fatal: [ubuntu]: FAILED! => {"changed": false, "msg": "Service is in unknown state", "status": {}}

The Agent is installed via .deb packages which are provided by Zabbix for each distribution. The error also occures when I try starting other services. So this shouldn't be a Zabbix related problem.

I also (try) to verify the service is running after applying the role with the following assertion in my verify.yml:

- name: Check if Zabbix Agent is running
  assert: 
    that: 'ansible_facts.services["zabbix-agent"].state == "started"'

...which currently is failing.

I did some research on Google and I looked at some of your Ansible Roles like ansible-role-nginx but can not locate my problem here. The nginx service is started exactly the same. When inside the container i can start the service manually by running: service zabbix-agent start. When running this command through Ansible's command module, the service is also started, but i would rather use the existing systemd or service module of Ansible because the command will not work like this on CentOS. Any ideas why it is not working? Do I have to adjust/extend the docker image?

This is probably an issue on my hand, but maybe you can point me into the right direction.

Thanks in advance!

geerlingguy commented 3 years ago

Make sure your molecule file contains these config lines: https://github.com/geerlingguy/ansible-role-nginx/blob/master/molecule/default/molecule.yml#L9-L13

If not, then systemd can't start correctly in the container.

p3l1 commented 3 years ago

Yeah, this was the issue. I forgot adding command: ${MOLECULE_DOCKER_COMMAND:-""}.

Thank you very much for your quick answer!