Debugging services in Ansible

Sometimes services don’t start and give an error like:

Unable to start service my_service: A dependency job for my_service.service failed. See 'journalctl -xe' for details.

Well, if you’re testing in CI, you can’t really access the instance that has an issue. So how to you troubleshoot this?

I use this pattern frequently:

- name: debug start my_service
    - name: start my_service
        name: "my_service"
        state: started
    - name: collect information
      command: "{{ item }}"
      register: my_service_collect_information
        - journalctl --unit my_service --no-pager
        - systemctl status my_service
    - name: show information
        msg: "{{ item }}"
      loop: "{{ my_service_collect_information.results }}"

What’s happening here?

Hope this helps you troubleshoot services in Travis of GitHub Actions.