I am using Ansible to get a service status on my machines.
Unfortunately I get a fatal
error that I am not so sure on how to fix. The code is working but this fatal
error is really bothering me.
Code:
- name: Edit application.properties
hosts: trainingShuttlesBJ
# gather_facts: true
tasks:
- name: Read service name from config.yml
include_vars:
file: config.yml
name: config_vars
- name: Get service status
command: systemctl is-active {{ config_vars.service_to_manage }}
register: service_status_before
changed_when: false
ignore_errors: true
- name: Debug service status
debug:
var: service_status_before.stdout
verbosity: 2
- name: Start service if not active
systemd:
name: "{{ config_vars.service_to_manage }}"
state: started
when: service_status_before.stdout != "active"
- name: Get service status after starting
command: systemctl is-active {{ config_vars.service_to_manage }}
register: service_status_after
changed_when: false
ignore_errors: true
- name: Display success message if service started
ansible.builtin.debug:
msg: "Table is ready for production. All steps succeeded successfully."
when: service_status_after.stdout == "active"
Error message:
TASK [Get service status] ****************************************************************************
fatal: [10.6.20.150]: FAILED! => {"changed": false, "cmd": ["systemctl", "is-active", "dealer-tool"], "delta": "0:00:00.011135", "end": "2023-08-31 10:07:33.137622", "msg": "non-zero return code", "rc": 3, "start": "2023-08-31 10:07:33.126487", "stderr": "", "stderr_lines": [], "stdout": "inactive", "stdout_lines": ["inactive"]}
...ignoring