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
  block:
    - name: start my_service
      service:
        name: ""
        state: started
  rescue:
    - name: collect information
      command: ""
      register: my_service_collect_information
      loop:
        - journalxtl -xe
        - systemctl status 
    - name: show information
      debug:
        msg: ""
      loop: ""

What’s happening here?

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