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

add win_reboot action #15314

Merged
merged 1 commit into from
Apr 25, 2016
Merged

add win_reboot action #15314

merged 1 commit into from
Apr 25, 2016

Conversation

nitzmahone
Copy link
Member

ISSUE TYPE
  • Feature Pull Request
ANSIBLE VERSION
ansible 2.1.0 (detached HEAD 6c007afcfa) last updated 2016/04/06 12:05:21 (GMT -700)
  lib/ansible/modules/core: (win_reboot 8a3e2ec20f) last updated 2016/04/06 12:07:22 (GMT -700)
  lib/ansible/modules/extras: (detached HEAD 7c3999a92a) last updated 2016/04/04 08:31:53 (GMT -700)
  config file =
  configured module search path = Default w/o overrides
SUMMARY

Adds win_reboot action to wrap the several necessary tasks to reboot a windows box and wait for it to come back up into a single task.

Docs are at ansible/ansible-modules-core#3376

@nitzmahone
Copy link
Member Author

@trondhindenes @jhawkesworth as promised - review/feedback appreciated!

if task_vars is None:
task_vars = dict()

# TODO: allow override via task args
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you have already done this TODO

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, oh yeah- I should probably remove the TODOs as I do them...

@nitzmahone nitzmahone added this to the 2.1.0 milestone Apr 8, 2016
@albertux
Copy link

@nitzmahone
In your file: lib/ansible/plugins/action/win_reboot.py add:

from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

@msheiny
Copy link
Contributor

msheiny commented Apr 11, 2016

I have a kind of weird edge case that I'm not sure is worth addressing. Running Virtualbox 5.0.16 r105871 under Linux. I'm testing against a VM under NAT networking and connecting through a port forward. Upon reboot, Virtualbox keeps the forwarded port open even though it is closed on the guest VM. This leaves this task stuck checking for the port to close which it never will. I did a quick hack around this by adding an extra variable for me to test locally, skip_shutdown_check = False which just skips the raise_if_port_open check and then waits pre_reboot_delay_sec+5 seconds before trying the connection again. Yeah, kind of hacky but it fixed the problem for me and possible others testing against virtualbox NAT networking.

        try:
            if not skip_reboot_check:
                self.do_until_success_or_timeout(raise_if_port_open, shutdown_timeout_sec, what_desc="winrm port down")
            else: time.sleep(pre_reboot_delay_sec+5)

            def connect_winrm_port():
                sock = socket.create_connection((winrm_host, winrm_port), connect_timeout_sec)
                sock.close()

also includes WinRM connection plugin change to support connection reset
@nitzmahone
Copy link
Member Author

@msheiny - one of the methods that I've considered for this (reflected in one of the FUTURE comments in the code) would probably address your situation nicely: sample the last boot time, then poll for it to change, ignoring failures, for up to reboot_timeout_sec. That optimizes it so you're not waiting any longer than you have to, as well as only making one "loop" in the code instead of three, but still ensuring that the machine did in fact reboot. You've pointed out another great reason for that behavior (I had a couple in mind already), so I'm thinking I'll just change it over to that.

@jhawkesworth
Copy link
Contributor

Just to say I have run this successfully against a Server 2012 R2 test vm.

@nitzmahone
Copy link
Member Author

May re-address later, but there are a couple of issues with switching to the high-level-only reboot, and I'd rather get it out there for the masses...

@nitzmahone nitzmahone merged commit 2becd79 into ansible:devel Apr 25, 2016
@jhawkesworth
Copy link
Contributor

Thanks for merging (I've started using this a bit already)!

@dagwieers dagwieers added the windows Windows community label Feb 11, 2019
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
windows Windows community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants