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?
blockis a grouping of tasks.
rescueruns when the initial task (
start my_service) fails. It has two tasks.
- The task
collect informationruns a few commands, add extra is you know more and saves the results in
- The task
show informationdisplays the saved result. Because
collect informationhas a loop, the variable has
.resultsappended, which is a list to needs to be looped over.
Hope this helps you troubleshoot services in Travis of Google Actions.