github.com/hashicorp/packer@v1.14.3/website/content/docs/provisioners/windows-shell.mdx (about)

     1  ---
     2  description: |
     3    The `windows-shell` provisioner runs commands on Windows using the `cmd`
     4    shell. Learn how to use the `windows-shell` provisioner.
     5  page_title: windows-shell provisioner reference
     6  ---
     7  
     8  <BadgesHeader>
     9    <PluginBadge type="official" />
    10  </BadgesHeader>
    11  
    12  # `windows-shell` provisioner
    13  
    14  The `windows-shell` Packer provisioner runs commands on a Windows machine using
    15  `cmd`. The provisioner is designed to communicate with machines running WinRM.
    16  
    17  ## Basic Example
    18  
    19  The example below is fully functional.
    20  
    21  <Tabs>
    22  <Tab heading="HCL2">
    23  
    24  ```hcl
    25  provisioner "windows-shell" {
    26    inline = ["dir c:\\"]
    27  }
    28  ```
    29  
    30  </Tab>
    31  <Tab heading="JSON">
    32  
    33  ```json
    34  {
    35    "type": "windows-shell",
    36    "inline": ["dir c:\\"]
    37  }
    38  ```
    39  
    40  </Tab>
    41  </Tabs>
    42  
    43  ## Configuration Reference
    44  
    45  @include 'provisioners/shell-config.mdx'
    46  
    47  - `env` (map of strings) - A map of key/value pairs to inject prior to the
    48    execute_command. Packer injects some environmental variables by default into
    49    the environment, as well, which are covered in the section below. Duplicate
    50    `env` settings override `environment_vars` settings.
    51  
    52  - `environment_vars` (array of strings) - An array of key/value pairs to
    53    inject prior to the execute_command. The format should be `key=value`.
    54    Packer injects some environmental variables by default into the
    55    environment, as well, which are covered in the section below.
    56  
    57  - `execute_command` (string) - The command to use to execute the script. By
    58    default this is `{{ .Vars }}"{{ .Path }}"`. The value of this is treated as
    59    [template engine](/packer/docs/templates/legacy_json_templates/engine). This is a
    60    [template engine](/packer/docs/templates/legacy_json_templates/engine). Therefore, you may
    61    use user variables and template functions in this field. In addition, there
    62    are two available extra variables:
    63  
    64    - `Path` is the path to the script to run
    65    - `Vars` is the list of `environment_vars`, if configured.
    66  
    67  - `remote_path` (string) - The path where the script will be uploaded to in
    68    the machine. This defaults to "c:/Windows/Temp/script.bat". This value must
    69    be a writable location and any parent directories must already exist.
    70  
    71  - `start_retry_timeout` (string) - The amount of time to attempt to _start_
    72    the remote process. By default this is "5m" or 5 minutes. This setting
    73    exists in order to deal with times when SSH may restart, such as a system
    74    reboot. Set this to a higher value if reboots take a longer amount of time.
    75  
    76  @include 'provisioners/common-config.mdx'
    77  
    78  ## Default Environmental Variables
    79  
    80  In addition to being able to specify custom environmental variables using the
    81  `environment_vars` configuration, the provisioner automatically defines certain
    82  commonly useful environmental variables:
    83  
    84  - `PACKER_BUILD_NAME` is set to the [name of the
    85    build](/packer/docs/templates/legacy_json_templates/builders#named-builds) that Packer is running.
    86    This is most useful when Packer is making multiple builds and you want to
    87    distinguish them slightly from a common provisioning script.
    88  
    89  - `PACKER_BUILDER_TYPE` is the type of the builder that was used to create
    90    the machine that the script is running on. This is useful if you want to
    91    run only certain parts of the script on systems built with certain
    92    builders.
    93  
    94  - `PACKER_HTTP_ADDR` If using a builder that provides an HTTP server for file
    95    transfer (such as `hyperv`, `parallels`, `qemu`, `virtualbox`, and `vmware`), this
    96    will be set to the address. You can use this address in your provisioner to
    97    download large files over HTTP. This may be useful if you're experiencing
    98    slower speeds using the default file provisioner. A file provisioner using
    99    the `winrm` communicator may experience these types of difficulties.