geerlingguy / ansible-role-nginx

Ansible Role - Nginx

Home Page:https://galaxy.ansible.com/geerlingguy/nginx/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`molecule test` failing on "Ensure nginx is started..."

chrrrles opened this issue · comments

Hello Geerlingguy,

I am extending your molecule test coverage for a project, and I am not able to advance past the 'converge' test action. Currently testing through the WSL on Windows 10, and I am not sure if my environment is causing the test to fail -- Are you able to run this test succesfully?

$ molecule test
--> Validating schema /home/charles/Dev/kotohikihama/meta-configuration/roles/geerlingguy.nginx/molecule/default/molecule.yml.
Validation completed successfully.

<SNIP>

--> Scenario: 'default'                                                                                                                                                                                                              [54/762]--> Action: 'prepare'
Skipping, prepare playbook not configured.
--> Scenario: 'default'
--> Action: 'converge'

    PLAY [Converge] ****************************************************************

    TASK [Gathering Facts] *********************************************************
    ok: [instance]

    TASK [Update apt cache.] *******************************************************
    skipping: [instance]

    TASK [geerlingguy.nginx : Include OS-specific variables.] **********************
    ok: [instance]

    TASK [geerlingguy.nginx : Define nginx_user.] **********************************
    ok: [instance]

    TASK [geerlingguy.nginx : include_tasks] ***************************************
    included: /home/charles/Dev/kotohikihama/meta-configuration/roles/geerlingguy.nginx/tasks/setup-RedHat.yml for instance

    TASK [geerlingguy.nginx : Enable nginx repo.] **********************************
    changed: [instance]

    TASK [geerlingguy.nginx : Ensure nginx is installed.] **************************
    changed: [instance]

    TASK [geerlingguy.nginx : include_tasks] ***************************************
    skipping: [instance]

    TASK [geerlingguy.nginx : include_tasks] ***************************************
    skipping: [instance]

    TASK [geerlingguy.nginx : include_tasks] ***************************************
    skipping: [instance]

    TASK [geerlingguy.nginx : include_tasks] ***************************************
    skipping: [instance]

    TASK [geerlingguy.nginx : include_tasks] ***************************************
    skipping: [instance]

    TASK [geerlingguy.nginx : Remove default nginx vhost config file (if configured).] ***
    changed: [instance]

    TASK [geerlingguy.nginx : Ensure nginx_vhost_path exists.] *********************
    ok: [instance]

    TASK [geerlingguy.nginx : Add managed vhost config files.] *********************
    changed: [instance] => (item={u'root': u'/var/www/test', u'server_name': u'test.dev'})

    TASK [geerlingguy.nginx : Remove managed vhost config files.] ******************
    skipping: [instance] => (item={u'root': u'/var/www/test', u'server_name': u'test.dev'})

    TASK [geerlingguy.nginx : Remove legacy vhosts.conf file.] *********************
    ok: [instance]

    TASK [geerlingguy.nginx : Copy nginx configuration in place.] ******************
    changed: [instance]

    TASK [geerlingguy.nginx : Ensure nginx is started and enabled to start at boot.] ***
    fatal: [instance]: FAILED! => {"changed": false, "msg": "Could not find the requested service nginx: host"}

    RUNNING HANDLER [geerlingguy.nginx : restart nginx] ****************************

    RUNNING HANDLER [geerlingguy.nginx : reload nginx] *****************************

    PLAY RECAP *********************************************************************
    instance                   : ok=11   changed=5    unreachable=0    failed=1


ERROR:
An error occurred during the test sequence action: 'converge'. Cleaning up.

Further experimenting, I have a successful test run after adding a debian8 target platform and extra capabilities.
molecule.yml:

platforms:
  - name: centos-instance
    image: geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible
    command: ${MOLECULE_DOCKER_COMMAND:-"sleep infinity"}
    privileged: true
    pre_build_image: true
    cap_add:
      - SYS_ADMIN
      - SYS_TIME
  - name: debian-instance
    image: geerlingguy/docker-debian8-ansible
    command: ${MOLECULE_DOCKER_COMMAND:-"sleep infinity"}
    privileged: true
    pre_build_image: true
    cap_add:
      - SYS_ADMIN
      - SYS_TIME
$ molecule test

<SNIP>

    TASK [geerlingguy.nginx : Ensure nginx is started and enabled to start at boot.] ***
    fatal: [centos-instance]: FAILED! => {"changed": false, "msg": "Could not find the requested service nginx: host"}
    changed: [debian-instance]

    RUNNING HANDLER [geerlingguy.nginx : restart nginx] ****************************
    changed: [debian-instance]

    RUNNING HANDLER [geerlingguy.nginx : reload nginx] *****************************
    changed: [debian-instance]

    PLAY RECAP *********************************************************************
    centos-instance            : ok=11   changed=5    unreachable=0    failed=1
    debian-instance            : ok=15   changed=7    unreachable=0    failed=0

What kind of Docker base image are you using? Most Docker base images don't have a service manager like initv or systemd, so things that use the service module will fail.

See this role's built-in Molecule tests for examples of working builds:

https://github.com/geerlingguy/ansible-role-nginx/tree/master/molecule/default

It currently runs CI tests every week (and on every commit and PR) for the following OSes:

  • centos7
  • ubuntu1804
  • ubuntu1604
  • debian9
  • debian8

The last set of tests ran successfully 4 days ago: https://travis-ci.org/geerlingguy/ansible-role-nginx

Thanks! I was working with an older fork without the changes in your test optimization commit.