180 words — 1 minutes read

Fix service registration with Ansible on Debian

I recently discovered a problem when creating a provisioning script for Ghost with Ansible 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
    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.


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.
    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 }}"
    - "defaults"
    - "enable"
  notify: ghost - restart service
Lars Fischer

IT. Aerophonist. Autor ohne Werk.