Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

win_shutdown #406

Closed
lucab85 opened this issue Aug 29, 2022 · 3 comments
Closed

win_shutdown #406

lucab85 opened this issue Aug 29, 2022 · 3 comments

Comments

@lucab85
Copy link

lucab85 commented Aug 29, 2022

SUMMARY

Implement a win_shutdown module to shut down a remote system. Another idea is to implement as parameter for win_reboot ansible module

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

ansible.windows.win_reboot

ADDITIONAL INFORMATION

None

@nicolai-hornung-bl
Copy link

This would probably fit best in a win_powerstate module that combines functionality from community.windows.win_wakeonlan and ansible.windows.win_reboot to offer the states: rebooted, started, stopped.

@watsonb
Copy link

watsonb commented Sep 9, 2022

Shutdown modules have been discussed numerous times in the past and are typically shot down due to several reasons, including but not limited to:

  1. How do you verify idempotence? If on a second run you cannot connect to the remote computer, is it assumed good? You'll get an unreachable error before the module even sees it.
  2. How would the module get feedback from the remote system if it is in fact shutting down, even on the initial task execution? This could lead to the task "hanging"

If you're working with a virtual machine, it is preferred to use modules that interact with the hypervisor (e.g. community.vmware) or cloud (e.g. azure.azcollection) to instruct the platform to power off the VM. This is more "desired state" as you can later query the platform via the same modules to ensure the machine is still down.

If you really want to remotely shutdown the machine, I propose using an async win_command or win_shell call with the Windows built-in shutdown commands and appropriate flags mentioned here:

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/shutdown

https://docs.ansible.com/ansible/latest/user_guide/playbooks_async.html#run-tasks-concurrently-poll-0

@jborean93
Copy link
Collaborator

jborean93 commented Sep 20, 2022

As per the above, this isn't something that is idempotent in Ansible and has been mentioned before the simple workaround of calling win_command: shutdown.exe /s /t 10 with a fire and forget async (poll: 0) is a simple enough workaround for people who truly need such a feature.

- name: shutdown host
  win_command: shutdown.exe /s /f /t 5
  async: 30
  poll: 0

# This is dependent on the transport you are using the port may differ for WinRM HTTPS or SSH
- name: wait for 
  wait_for:
    host: '{{ hostvars[inventory_hostname]["ansible_host"] | default(inventory_hostname) }}'
    port: 5985
    state: stopped
  delegate_to: localhost

@jborean93 jborean93 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants