Systemd service status check

106 views
Skip to first unread message

Narmada Karthika

unread,
May 30, 2023, 6:07:23 PM5/30/23
to Ansible Project
I am trying to run my playbook to check/restart/stop kestrel service on given node. I am able to ping that node using ansible but when running the task its is failing with connection timeout error. 
here is the playbook
---
- name: check kestrel service
  hosts: lin_dev
  become: true
  gather_facts: no
  vars:
    kestrelservicename: kestrel-api.service
   
  tasks:
    - name: check status of kestrel service
      ansible.builtin.service:
        name: "{{ kestrelservicename }}"
        state: started
        enabled: no
      become_user: root
      timeout: 300




error is

"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "msg": "Unable to disable service kestrel-api.service: Failed to execute operation: Connection timed out\n"}

"Kosala Atapattu (කෝසල අතපත්තු)"

unread,
May 30, 2023, 6:13:40 PM5/30/23
to ansible...@googlegroups.com
Just wonder whether you can disable that service manually in 5 mins?

Sent from my iPhone

On 31/05/2023, at 10:07 AM, Narmada Karthika <chitt...@gmail.com> wrote:

I am trying to run my playbook to check/restart/stop kestrel service on given node. I am able to ping that node using ansible but when running the task its is failing with connection timeout error. 
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3aed1068-3bbe-4426-b98a-fc9b2818cdadn%40googlegroups.com.

Narmada Karthika

unread,
May 30, 2023, 6:20:25 PM5/30/23
to Ansible Project
yea, I tried that option just to check if its timing out before it is disabling
btw, I got it fixed I changed the user: root at the top level instead of play level 

Narmada Karthika

unread,
May 30, 2023, 6:21:06 PM5/30/23
to Ansible Project
But I had one more question here, can I delete the kestrel service using ansible??

On Tuesday, May 30, 2023 at 3:13:40 PM UTC-7 "Kosala Atapattu (කෝසල අතපත්තු)" wrote:

"Kosala Atapattu (කෝසල අතපත්තු)"

unread,
May 30, 2023, 6:24:38 PM5/30/23
to ansible...@googlegroups.com


Sent from my iPhone

On 31/05/2023, at 10:20 AM, Narmada Karthika <chitt...@gmail.com> wrote:

yea, I tried that option just to check if its timing out before it is disabling
btw, I got it fixed I changed the user: root at the top level instead of play level 


Aha, you can also opt to become root in task level, with sudo as well. 



Narmada Karthika

unread,
May 30, 2023, 6:26:19 PM5/30/23
to Ansible Project
Right, I had it in the task level, some how it did not work.

Kosala Atapattu

unread,
May 30, 2023, 7:10:03 PM5/30/23
to ansible...@googlegroups.com
Just wonder whether the user you initially ran on had sudo access...


Kosala




Narmada Karthika

unread,
May 30, 2023, 8:04:53 PM5/30/23
to Ansible Project
it has.. 

coming to my other question, can I delete a service on linux using ansible..

Kosala Atapattu

unread,
May 30, 2023, 8:15:52 PM5/30/23
to ansible...@googlegroups.com
Don't believe you can from systemctl commands, but just like we create service definitions, we can delete them as well. I'm thinking:

1. Stop the service, and disable
2. Track down the service definition file, delete it
3. Perform a systemctl daemon-reload... might have to do this as a command.

But, why delete? DIsable is not good enough?

Kosala




Narmada Karthika

unread,
May 30, 2023, 8:19:53 PM5/30/23
to ansible...@googlegroups.com
There are applications migrating from vms to k8s, so we don't need to have service kept disabled on old systems, may cause confusion and maintenance.



--
 Thanks,
Narmada Karthika Chitturi
 

Narmada Karthika

unread,
May 31, 2023, 1:59:52 PM5/31/23
to Ansible Project
btw, i got this working .. thought it would be helpful for someone, so posting it..
---
- name: Delete kestrel service
  hosts: lin_dev
  become: true
  user: root
  gather_facts: no
  vars:
    kestrelservicename: kestrel-api.service
   
  tasks:
    - name: Delete kestrel service
      ansible.builtin.systemd:
        name: "{{ kestrelservicename }}"
        daemon_reload: true  
       

    - name: Remove directory content
      become: yes
      file:
        path: "/etc/systemd/system/{{ kestrelservicename }}"
        state: absent
Reply all
Reply to author
Forward
0 new messages