• Infrastructure
    • terraform
    • packer
  • Networking
    • consul
  • Security
    • vault
    • boundary
  • Applications
    • nomad
    • waypoint
    • vagrant
  • HashiCorp Cloud Platform

    A fully managed platform to automate infrastructure on any cloud with HashiCorp products.

    • consul
    • terraform
    • vault
    • packerbeta
    Visit cloud.hashicorp.com
  • Overview
  • Tutorials
  • Docs
  • Plugins
  • Community
GitHubInstall PackerTry HCP Packer
    • v1.8.x (latest)
    • v1.7.x
    • v1.6.x
    • v1.5.x

  • Terminology
    • Overview
    • init
      • Overview
      • install
      • installed
      • remove
      • required
    • build
    • console
    • fix
    • fmt
    • inspect
    • validate
    • hcl2_upgrade
    • Overview
      • Overview
        • Overview
          • Overview
          • hcp_packer_registry
          • source
          • provisioner
          • post-processor
          • post-processors
        • locals
        • source
        • variable
        • packer
        • data
        • Overview
          • aws_secretsmanager
          • consul
          • env
          • vault
          • abs
          • ceil
          • floor
          • log
          • max
          • min
          • parseint
          • pow
          • signum
          • chomp
          • format
          • formatlist
          • indent
          • join
          • lower
          • replace
          • regex_replace
          • regex
          • regexall
          • split
          • strrev
          • substr
          • title
          • trim
          • trimprefix
          • trimsuffix
          • trimspace
          • upper
          • chunklist
          • coalesce
          • coalescelist
          • compact
          • concat
          • contains
          • distinct
          • element
          • flatten
          • index
          • keys
          • length
          • lookup
          • merge
          • range
          • reverse
          • setintersection
          • setproduct
          • setunion
          • slice
          • sort
          • values
          • zipmap
          • base64decode
          • base64encode
          • csvdecode
          • jsondecode
          • jsonencode
          • urlencode
          • yamldecode
          • yamlencode
          • abspath
          • basename
          • dirname
          • file
          • fileexists
          • fileset
          • pathexpand
          • templatefile
          • formatdate
          • timeadd
          • timestamp
          • legacy_isotime
          • legacy_strftime
          • bcrypt
          • md5
          • rsadecrypt
          • sha1
          • sha256
          • sha512
          • uuidv4
          • uuidv5
          • cidrhost
          • cidrnetmask
          • cidrsubnet
          • cidrsubnets
          • can
          • convert
          • try
      • Variables
      • Locals
      • Contextual Variables
      • Data Sources
      • Path Variables
      • Syntax
      • Only Except
      • Expressions
      • JSON Syntax
      • Overview
      • Builders
      • Communicators
      • Engine
      • Post-Processors
      • Provisioners
      • User Variables

    • Overview
    • SSH
    • WINRM
    • Overview
    • File
    • Null
    • Custom
    • Community-Supported
    • Overview
      • Overview
      • Iteration
      • Image
      • Image-Deprecated
    • Http
    • Overview
    • Breakpoint
    • File
    • PowerShell
    • Shell
    • Shell (Local)
    • Windows Shell
    • Windows Restart
    • Custom
    • Community-Supported
    • Overview
    • Artifice
    • Compress
    • Checksum
    • Manifest
    • Shell (Local)
    • Community-Supported
  • External Plugins

  • Installing Packer
  • Configuring Packer

    • Overview
      • Overview
      • Custom Builders
      • Custom Post-Processors
      • Custom Provisioners
      • Custom Data Sources
    • HCP Packer Support
  • Integration Program

  • Debugging
  • HCP Packer
Type '/' to Search
Official

»Windows Restart Provisioner

Type: windows-restart

The Windows restart provisioner initiates a reboot on a Windows machine and waits for the machine to come back online.

The Windows provisioning process often requires multiple reboots, and this provisioner helps to ease that process.

Packer expects the machine to be ready to continue provisioning after it reboots. Packer detects that the reboot has completed by making an RPC call through the Windows Remote Management (WinRM) service, not by ACPI functions, so Windows must be completely booted in order to continue.

»Basic Example

The example below is fully functional.

provisioner "windows-restart" {}
provisioner "windows-restart" {}

»Configuration Reference

The reference of available configuration options is listed below.

Optional parameters:

  • check_registry (bool) - if true, checks for several registry keys that indicate that the system is going to reboot. This is useful if an installation kicks off a reboot and you want the provisioner to wait for that reboot to complete before reconnecting. Please note that this option is a beta feature, and we generally recommend that you finish installs that auto-reboot (like Windows Updates) during your autounattend phase before the winrm provisioner connects.

  • registry_keys (array of strings) - if check-registry is true, windows-restart will not reconnect until after all of the listed keys are no longer present in the registry.

  default:

      var DefaultRegistryKeys = []string{
        "HKLM:SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootPending",
        "HKLM:SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\PackagesPending",
        "HKLM:Software\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootInProgress",
      }
  default:

      var DefaultRegistryKeys = []string{
        "HKLM:SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootPending",
        "HKLM:SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\PackagesPending",
        "HKLM:Software\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootInProgress",
      }
  • restart_command (string) - The command to execute to initiate the restart. By default this is shutdown /r /f /t 0 /c "packer restart".

  • restart_check_command (string) - The command to run after executing restart_command to check if the guest machine has restarted. This command will retry until the connection to the guest machine has been restored or restart_timeout has exceeded.

provisioner "windows-restart" {
  restart_check_command = "powershell -command \"& {Write-Output 'restarted.'}\""
}
provisioner "windows-restart" {
  restart_check_command = "powershell -command \"& {Write-Output 'restarted.'}\""
}
  • restart_timeout (string) - The timeout to wait for the restart. By default this is 5 minutes. Example value: 5m. If you are installing updates or have a lot of startup services, you will probably need to increase this duration.

Parameters common to all provisioners:

  • pause_before (duration) - Sleep for duration before execution.

  • max_retries (int) - Max times the provisioner will retry in case of failure. Defaults to zero (0). Zero means an error will not be retried.

  • only (array of string) - Only run the provisioner for listed builder(s) by name.

  • override (object) - Override the builder with different settings for a specific builder, eg :

    In HCL2:

    source "null" "example1" {
      communicator = "none"
    }
    
    source "null" "example2" {
      communicator = "none"
    }
    
    build {
      sources = ["source.null.example1", "source.null.example2"]
      provisioner "shell-local" {
        inline = ["echo not overridden"]
        override = {
          example1 = {
            inline = ["echo yes overridden"]
          }
        }
      }
    }
    
    source "null" "example1" {
      communicator = "none"
    }
    
    source "null" "example2" {
      communicator = "none"
    }
    
    build {
      sources = ["source.null.example1", "source.null.example2"]
      provisioner "shell-local" {
        inline = ["echo not overridden"]
        override = {
          example1 = {
            inline = ["echo yes overridden"]
          }
        }
      }
    }
    

    In JSON:

    {
      "builders": [
        {
          "type": "null",
          "name": "example1",
          "communicator": "none"
        },
        {
          "type": "null",
          "name": "example2",
          "communicator": "none"
        }
      ],
      "provisioners": [
        {
          "type": "shell-local",
          "inline": ["echo not overridden"],
          "override": {
            "example1": {
              "inline": ["echo yes overridden"]
            }
          }
        }
      ]
    }
    
    {
      "builders": [
        {
          "type": "null",
          "name": "example1",
          "communicator": "none"
        },
        {
          "type": "null",
          "name": "example2",
          "communicator": "none"
        }
      ],
      "provisioners": [
        {
          "type": "shell-local",
          "inline": ["echo not overridden"],
          "override": {
            "example1": {
              "inline": ["echo yes overridden"]
            }
          }
        }
      ]
    }
    
  • timeout (duration) - If the provisioner takes more than for example 1h10m1s or 10m to finish, the provisioner will timeout and fail.

github logoEdit this page
IntroGuidesDocsCommunityPrivacySecurityPress KitConsent Manager