2

I am trying to clear a hands on in HackerRank, where the task is to stop and start the service named ssh using service module. I have used the below code.

- name: "Stop ssh"
  service:
    name: ssh
    state: stopped
- name: "start ssh"
  service:
    name: ssh
    state: started

Can you please guide me to clear the hands on.

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Mahesh
  • 48
  • 5

1 Answers1

1

The service handling ssh on Linux is called sshd like a lot of other services, where the d stands for daemon.

So your correct tasks would be:

- name: Stop ssh
  service:
    name: sshd
    state: stopped
- name: Start ssh
  service:
    name: sshd
    state: started

This said, since Ansible connects through ssh, I am unsure how this will really react when the service is stopped.

Most of the linux services, though do also have a restart instruction, that you can also use in Ansible, with the state value restarted.

- name: Restart ssh
  service:
    name: sshd
    state: restarted
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83