---
# handlers file for ansible-role-cuda
- name: reload systemd unit files
  systemd:
    daemon-reload: yes
  when: ansible_connection != 'chroot'

- name: Initialize the GPUs
  command: /bin/bash /usr/local/bin/cuda_init.sh
  when:
    - cuda_init|bool
    - cuda_init_restart_service|bool
    - ansible_connection != 'chroot'

- name: Restart cuda_init service
  service:
    name: cuda_init
    state: restarted
  when:
    - cuda_init|bool
    - cuda_init_restart_service|bool
    - ansible_service_mgr == "systemd"

- name: ZZ CUDA Restart server
  command: sleep 2 && /sbin/shutdown -r now "Node software upgrade reboot"
  async: 1
  poll: 0
  ignore_errors: true
  when:
    - cuda_packages_installation.changed
    - cuda_restart_node_on_install|bool
    - ansible_connection != 'chroot'

# define the variable running_as_ansible_pull in the ansible-pull playbook, like local.yml 
- name: ZZ CUDA Wait for server to restart
  wait_for:
    host: "{{ ansible_ssh_host | default(inventory_hostname) }}"
    state: started
    delay: 30
    timeout: 300
  connection: local
  become: false
  when:
    - cuda_restart_node_on_install|bool
    - (running_as_ansible_pull is not defined or running_as_ansible_pull == False)
    - ansible_connection != 'chroot'

# vim:ft=ansible:

---
# handlers file for ansible-role-cuda
- name: reload systemd unit files
  shell: systemctl daemon-reload
  when: ansible_connection != 'chroot'

- name: Initialize the GPUs
  command: /bin/bash /usr/local/bin/cuda_init.sh
  when:
    - cuda_init|bool
    - cuda_init_restart_service|bool
    - ansible_connection != 'chroot'

- name: Restart cuda_init service
  service:
    name: cuda_init
    state: restarted
  when:
    - cuda_init|bool
    - cuda_init_restart_service|bool
    - ansible_service_mgr == "systemd"

- name: ZZ CUDA Restart server
  command: sleep 2 && /sbin/shutdown -r now "Node software upgrade reboot"
  async: 1
  poll: 0
  ignore_errors: true
  when:
    - cuda_packages_installation.changed
    - cuda_restart_node_on_install|bool
    - ansible_connection != 'chroot'

# define the variable running_as_ansible_pull in the ansible-pull playbook, like local.yml 
- name: ZZ CUDA Wait for server to restart
  wait_for:
    host: "{{ ansible_ssh_host | default(inventory_hostname) }}"
    state: started
    delay: 30
    timeout: 300
  connection: local
  become: false
  when:
    - cuda_restart_node_on_install|bool
    - (running_as_ansible_pull is not defined or running_as_ansible_pull == False)
    - ansible_connection != 'chroot'

# vim:ft=ansible:

Revert "use systemd module instead of shell"
Revert "use systemd module instead of shell"

This reverts commit 622eea697a18496ab7316787ed020c64b0b95120.
