I recently discovered a problem when creating a provisioning script for Ghost with Ansible 2.2.1.0 on Debian 8 Jessie.

The problem happened after providing the init script for Ghost and starting the service.

The shell code would look like this:

sudo update-rc.d ghost defaults
sudo update-rc.d ghost enable
sudo service ghost start

The representation of the above in Ansible:

- name: install - enable Ghost service
      service:
        name: ghost
        enabled: yes
        state: started
      become: yes

On my Debian 8 based Vagrant testing instance starting the Ghost service always failed - starting the service only worked after restarting the Debian system.

Solution

To me this looks like a bug in Ansible not handling services with update-rc.d correctly.

I fixed the Ansible script by integrating the the two update-rc.d commands previously used with the shell variant.

---
    - name: service - Add system script for Ghost service.
      template:
        src: init.ghost.j2
        dest: "/etc/init.d/{{ ghost_service_name }}"
        owner: root
        group: root
        mode: 0755
    # Fix for Debian Jessie
    - shell: update-rc.d ghost "{{ item }}"
      with_items:
        - "defaults"
        - "enable"
      notify: ghost - restart service