I have a simple ansible playbook to get the status of the etcd service as below.
- name: Check if etcd service is running
command: systemctl status etcd
register: result
ignore_errors: yes
But at first this service might not be running
So I want to start the service if it is not running. So it must be a conditional check, here's what I did:
- name: showing report
debug:
var: result.ansible_facts.services["etcd.service"].state
But this gives the error as below:
TASK [showing report] ********************************************************** ok: [35.236.98.212] => { "result.ansible_facts.services["etcd.service"].state": "VARIABLE IS NOT DEFINED!"
How can I check the Status of the etcd service, and if it it not running I want to start the service and if it is already running, leave it as it is.
Can someone please help me?