summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorJordan Borean <jborean93@gmail.com>2019-03-08 10:38:02 +1000
committerMatt Davis <nitzmahone@users.noreply.github.com>2019-03-07 16:38:02 -0800
commit8ef2e6da05333f49988949f973e627b582a27beb (patch)
tree2453b235628fa3d75b58316397900bc1c0750b2f /docs
parentcdf475e830562554d92bcd7c5912c5b9980ccee7 (diff)
downloadansible-8ef2e6da05333f49988949f973e627b582a27beb.tar.gz
Add support for Windows hosts in the SSH connection plugin (#47732)
* Add support for Windows hosts in the SSH connection plugin * fix Python 2.6 unit test and sanity issues * fix up connection tests in CI, disable SCP for now * ensure we don't pollute the existing environment during the test * Add connection_windows_ssh to classifier * use test dir for inventory file * Required powershell as default shell and fix tests * Remove exlicit become_methods on connection * clarify console encoding comment * ignore recent SCP errors in integration tests * Add cmd shell type and added more tests * Fix some doc issues * revises windows faq * add anchors for windows links * revises windows setup page * Update changelogs/fragments/windows-ssh.yaml Co-Authored-By: jborean93 <jborean93@gmail.com>
Diffstat (limited to 'docs')
-rw-r--r--docs/docsite/rst/user_guide/windows.rst4
-rw-r--r--docs/docsite/rst/user_guide/windows_faq.rst109
-rw-r--r--docs/docsite/rst/user_guide/windows_setup.rst160
3 files changed, 200 insertions, 73 deletions
diff --git a/docs/docsite/rst/user_guide/windows.rst b/docs/docsite/rst/user_guide/windows.rst
index 6635383e49..4e01c3a44e 100644
--- a/docs/docsite/rst/user_guide/windows.rst
+++ b/docs/docsite/rst/user_guide/windows.rst
@@ -1,3 +1,5 @@
+.. _windows:
+
Windows Guides
``````````````
@@ -5,7 +7,7 @@ The following sections provide information on managing
Windows hosts with Ansible.
Because Windows is a non-POSIX-compliant operating system, there are differences between
-how Ansible interacts with them and the way Windows works. These guides will highlight
+how Ansible interacts with them and the way Windows works. These guides will highlight
some of the differences between Linux/Unix hosts and hosts running Windows.
.. toctree::
diff --git a/docs/docsite/rst/user_guide/windows_faq.rst b/docs/docsite/rst/user_guide/windows_faq.rst
index 68f82aa1b4..a45ea50f6e 100644
--- a/docs/docsite/rst/user_guide/windows_faq.rst
+++ b/docs/docsite/rst/user_guide/windows_faq.rst
@@ -1,3 +1,5 @@
+.. _windows_faq:
+
Windows Frequently Asked Questions
==================================
@@ -6,7 +8,7 @@ their answers.
.. note:: This document covers questions about managing Microsoft Windows servers with Ansible.
For questions about Ansible Core, please see the
- :ref:`FAQ page <ansible_faq>`.
+ :ref:`general FAQ page <ansible_faq>`.
Does Ansible work with Windows XP or Server 2003?
``````````````````````````````````````````````````
@@ -22,19 +24,19 @@ supported operating system versions are:
* Windows 8.1
* Windows 10
-Ansible also has minimum PowerShell version requirements - please see
-:doc:`windows_setup` for the latest information.
+Ansible also has minimum PowerShell version requirements - please see
+:ref:`windows_setup` for the latest information.
-Can I Manage Windows Nano Server?
-`````````````````````````````````
+Can I manage Windows Nano Server with Ansible?
+``````````````````````````````````````````````
Windows Nano Server is not currently supported by Ansible, since it does
not have access to the full .NET Framework that is used by the majority of the
modules and internal components.
Can Ansible run on Windows?
```````````````````````````
-No, Ansible cannot run on a Windows host natively and can only manage Windows hosts,
-but Ansible can be run under the Windows Subsystem for Linux (WSL).
+No, Ansible can only manage Windows hosts. Ansible cannot run on a Windows host
+natively, though it can run under the Windows Subsystem for Linux (WSL).
.. note:: The Windows Subsystem for Linux is not supported by Ansible and
should not be used for production systems.
@@ -60,16 +62,20 @@ installed version and then clone the git repo.
# To enable Ansible on login, run the following
echo ". ~/ansible/hacking/env-setup -q' >> ~/.bashrc
-Can I use SSH keys to authenticate?
-```````````````````````````````````
-Windows uses WinRM as the transport protocol. WinRM supports a wide range of
-authentication options. The closet option to SSH keys is to use the certificate
-authentication option which maps an X509 certificate to a local user.
+Can I use SSH keys to authenticate to Windows hosts?
+````````````````````````````````````````````````````
+SSH keys are not supported when using the WinRM or PSRP connection plugins.
+These connection plugins support X509 certificates for authentication instead
+of the SSH key pairs that SSH supports.
-The way that these certificates are generated and mapped to a user is different
-from the SSH implementation; consult the :doc:`windows_winrm` documentation for
+The way X509 certificates are generated and mapped to a user is different
+from the SSH implementation; consult the :ref:`windows_winrm` documentation for
more information.
+Ansible 2.8 has added experimental support for using the SSH connection plugin,
+which supports authentication with SSH keys, to connect to Windows servers. See `this question <windows_faq_ssh>`
+for more information.
+
.. _windows_faq_winrm:
Why can I run a command locally that does not work under Ansible?
@@ -82,7 +88,7 @@ running a command locally in these ways:
delegate the user's credentials to a network resource, causing ``Access is
Denied`` errors.
-* All processes run under WinRM are in a non-interactive session. Applications
+* All processes run under WinRM are in a non-interactive session. Applications
that require an interactive session will not work.
* When running through WinRM, Windows restricts access to internal Windows
@@ -93,7 +99,7 @@ Some ways to bypass these restrictions are to:
* Use ``become``, which runs a command as it would when run locally. This will
bypass most WinRM restrictions, as Windows is unaware the process is running
- under WinRM when ``become`` is used. See the :doc:`become` documentation for more
+ under WinRM when ``become`` is used. See the :ref:`become` documentation for more
information.
* Use a scheduled task, which can be created with ``win_scheduled_task``. Like
@@ -107,15 +113,15 @@ Some ways to bypass these restrictions are to:
authentication option that supports credential delegation can be used. Both
CredSSP and Kerberos with credential delegation enabled can support this.
-See :doc:`become` more info on how to use become. The limitations section at
-:doc:`windows_winrm` has more details around WinRM limitations.
+See :ref:`become` more info on how to use become. The limitations section at
+:ref:`windows_winrm` has more details around WinRM limitations.
-This program won't install with Ansible
-```````````````````````````````````````
+This program won't install on Windows with Ansible
+``````````````````````````````````````````````````
See :ref:`this question <windows_faq_winrm>` for more information about WinRM limitations.
-What modules are available?
-```````````````````````````
+What Windows modules are available?
+```````````````````````````````````
Most of the Ansible modules in Ansible Core are written for a combination of
Linux/Unix machines and arbitrary web services. These modules are written in
Python and most of them do not work on Windows.
@@ -147,39 +153,54 @@ In addition, the following Ansible Core modules/action-plugins work with Windows
* template (also: win_template)
* wait_for_connection
-Can I run Python modules?
-`````````````````````````
+Can I run Python modules on Windows hosts?
+``````````````````````````````````````````
No, the WinRM connection protocol is set to use PowerShell modules, so Python
modules will not work. A way to bypass this issue to use
``delegate_to: localhost`` to run a Python module on the Ansible controller.
This is useful if during a playbook, an external service needs to be contacted
and there is no equivalent Windows module available.
-Can I connect over SSH?
-```````````````````````
-Microsoft has announced and is developing a fork of OpenSSH for Windows that
-allows remote manage of Windows servers through the SSH protocol instead of
-WinRM. While this can be installed and used right now for normal SSH clients,
-it is still in beta from Microsoft and the required functionality has not been
-developed within Ansible yet.
+.. _winrm_faq_ssh:
-There are future plans on adding this feature and this page will be updated
-once more information can be shared.
+Can I connect to Windows hosts over SSH?
+````````````````````````````````````````
+Ansible 2.8 has added experimental support for using the SSH connection plugin
+to manage Windows hosts. To connect to Windows hosts over SSH, you must install and configure the `Win32-OpenSSH <https://github.com/PowerShell/Win32-OpenSSH>`_
+fork that is in development with Microsoft on
+the Windows host(s). While most of the basics should work with SSH,
+``Win32-OpenSSH`` is rapidly changing, with new features added and bugs
+fixed in every release. It is highly recommend you install the latest release
+of ``Win32-OpenSSH`` from the GitHub Releases page when using it with Ansible
+on Windows hosts.
-Why is connecting to the host via ssh failing?
-``````````````````````````````````````````````
-When trying to connect to a Windows host and the output error indicates that
-SSH was used, then this is an indication that the connection vars are not set
-properly or the host is not inheriting them correctly.
+To use SSH as the connection to a Windows host, set the following variables in
+the inventory::
+
+ ansible_connection=ssh
+
+ # Set either cmd or powershell not both
+ ansible_shell_type=cmd
+ # ansible_shell_type=powershell
+
+The value for ``ansible_shell_type`` should either be ``cmd`` or ``powershell``.
+Use ``cmd`` if the ``DefaultShell`` has not been configured on the SSH service
+and ``powershell`` if that has been set as the ``DefaultShell``.
+
+Why is connecting to a Windows host via SSH failing?
+````````````````````````````````````````````````````
+Unless you are using ``Win32-OpenSSH`` as described above, you must connect to
+Windows hosts using :ref:`windows_winrm`. If your Ansible output indicates that
+SSH was used, either you did not set the connection vars properly or the host is not inheriting them correctly.
Make sure ``ansible_connection: winrm`` is set in the inventory for the Windows
-host.
+host(s).
Why are my credentials being rejected?
``````````````````````````````````````
This can be due to a myriad of reasons unrelated to incorrect credentials.
-See HTTP 401/Credentials Rejected at :doc:`windows_setup` for a more detailed
+See HTTP 401/Credentials Rejected at :ref:`windows_setup` for a more detailed
guide of this could mean.
Why am I getting an error SSL CERTIFICATE_VERIFY_FAILED?
@@ -196,13 +217,11 @@ host.
.. seealso::
- :doc:`index`
- The documentation index
- :doc:`windows`
+ :ref:`windows`
The Windows documentation index
- :doc:`playbooks`
+ :ref:`about_playbooks`
An introduction to playbooks
- :doc:`playbooks_best_practices`
+ :ref:`playbooks_best_practices`
Best practices advice
`User Mailing List <https://groups.google.com/group/ansible-project>`_
Have a question? Stop by the google group!
diff --git a/docs/docsite/rst/user_guide/windows_setup.rst b/docs/docsite/rst/user_guide/windows_setup.rst
index 965405e4e0..fcdfa12900 100644
--- a/docs/docsite/rst/user_guide/windows_setup.rst
+++ b/docs/docsite/rst/user_guide/windows_setup.rst
@@ -1,8 +1,10 @@
+.. _windows_setup:
+
Setting up a Windows Host
=========================
This document discusses the setup that is required before Ansible can communicate with a Microsoft Windows host.
-.. contents:: Topics
+.. contents::
:local:
Host Requirements
@@ -12,7 +14,7 @@ Windows host must meet the following requirements:
* Ansible's supported Windows versions generally match those under current
and extended support from Microsoft. Supported desktop OSs include
- Windows 7, 8.1, and 10, and supported server OSs are Windows Server 2008,
+ Windows 7, 8.1, and 10, and supported server OSs are Windows Server 2008,
2008 R2, 2012, 2012 R2, and 2016.
* Ansible requires PowerShell 3.0 or newer and at least .NET 4.0 to be
@@ -21,7 +23,7 @@ Windows host must meet the following requirements:
* A WinRM listener should be created and activated. More details for this can be
found below.
-.. Note:: While these are the base requirements for Ansible connectivity, some Ansible
+.. Note:: While these are the base requirements for Ansible connectivity, some Ansible
modules have additional requirements, such as a newer OS or PowerShell
version. Please consult the module's documentation page
to determine whether a host meets those requirements.
@@ -60,7 +62,7 @@ do this with the following PowerShell commands:
Remove-ItemProperty -Path $reg_winlogon_path -Name DefaultUserName -ErrorAction SilentlyContinue
Remove-ItemProperty -Path $reg_winlogon_path -Name DefaultPassword -ErrorAction SilentlyContinue
-The script works by checking to see what programs need to be installed
+The script works by checking to see what programs need to be installed
(such as .NET Framework 4.5.2) and what PowerShell version is required. If a reboot
is required and the ``username`` and ``password`` parameters are set, the
script will automatically reboot and logon when it comes back up from the
@@ -77,15 +79,15 @@ actions are required.
.. Note:: Windows Server 2008 can only install PowerShell 3.0; specifying a
newer version will result in the script failing.
-.. Note:: The ``username`` and ``password`` parameters are stored in plain text
- in the registry. Make sure the cleanup commands are run after the script finishes
+.. Note:: The ``username`` and ``password`` parameters are stored in plain text
+ in the registry. Make sure the cleanup commands are run after the script finishes
to ensure no credentials are still stored on the host.
WinRM Memory Hotfix
-------------------
When running on PowerShell v3.0, there is a bug with the WinRM service that
limits the amount of memory available to WinRM. Without this hotfix installed,
-Ansible will fail to execute certain commands on the Windows host. These
+Ansible will fail to execute certain commands on the Windows host. These
hotfixes should installed as part of the system bootstrapping or
imaging process. The script `Install-WMF3Hotfix.ps1 <https://github.com/jborean93/ansible-windows/blob/master/scripts/Install-WMF3Hotfix.ps1>`_ can be used to install the hotfix on affected hosts.
@@ -127,10 +129,10 @@ There are different switches and parameters (like ``-EnableCredSSP`` and
``-ForceNewSSLCert``) that can be set alongside this script. The documentation
for these options are located at the top of the script itself.
-.. Note:: The ConfigureRemotingForAnsible.ps1 script is intended for training and
+.. Note:: The ConfigureRemotingForAnsible.ps1 script is intended for training and
development purposes only and should not be used in a
- production environment, since it enables settings (like ``Basic`` authentication)
- that can be inherently insecure.
+ production environment, since it enables settings (like ``Basic`` authentication)
+ that can be inherently insecure.
WinRM Listener
--------------
@@ -193,7 +195,7 @@ the key options that are useful to understand are:
.. comment: Pygments powershell lexer does not support colons (i.e. URLs)
.. code-block:: guess
-
+
$thumbprint = "E6CDAA82EEAF2ECE8546E05DB7F3E01AA47D76CE"
Get-ChildItem -Path cert:\LocalMachine\My -Recurse | Where-Object { $_.Thumbprint -eq $thumbprint } | Select-Object *
@@ -204,12 +206,12 @@ There are three ways to set up a WinRM listener:
* Using ``winrm quickconfig`` for HTTP or
``winrm quickconfig -transport:https`` for HTTPS. This is the easiest option
to use when running outside of a domain environment and a simple listener is
- required. Unlike the other options, this process also has the added benefit of
- opening up the Firewall for the ports required and starts the WinRM service.
+ required. Unlike the other options, this process also has the added benefit of
+ opening up the Firewall for the ports required and starts the WinRM service.
-* Using Group Policy Objects. This is the best way to create a listener when the
- host is a member of a domain because the configuration is done automatically
- without any user input. For more information on group policy objects, see the
+* Using Group Policy Objects. This is the best way to create a listener when the
+ host is a member of a domain because the configuration is done automatically
+ without any user input. For more information on group policy objects, see the
`Group Policy Objects documentation <https://msdn.microsoft.com/en-us/library/aa374162(v=vs.85).aspx>`_.
* Using PowerShell to create the listener with a specific configuration. This
@@ -253,7 +255,7 @@ To remove a WinRM listener:
WinRM Service Options
---------------------
-There are a number of options that can be set to control the behavior of the WinRM service component,
+There are a number of options that can be set to control the behavior of the WinRM service component,
including authentication options and memory settings.
To get an output of the current service configuration options, run the
@@ -325,7 +327,7 @@ options are:
* ``Service\CertificateThumbprint``: This is the thumbprint of the certificate
used to encrypt the TLS channel used with CredSSP authentication. By default
- this is empty; a self-signed certificate is generated when the WinRM service
+ this is empty; a self-signed certificate is generated when the WinRM service
starts and is used in the TLS process.
* ``Winrs\MaxShellRunTime``: This is the maximum time, in milliseconds, that a
@@ -365,10 +367,10 @@ command can be used:
Common WinRM Issues
-------------------
Because WinRM has a wide range of configuration options, it can be difficult
-to setup and configure. Because of this complexity, issues that are shown by Ansible
-could in fact be issues with the host setup instead.
+to setup and configure. Because of this complexity, issues that are shown by Ansible
+could in fact be issues with the host setup instead.
-One easy way to determine whether a problem is a host issue is to
+One easy way to determine whether a problem is a host issue is to
run the following command from another Windows host to connect to the
target Windows host:
@@ -400,7 +402,7 @@ connection. Some things to check for this are:
``ansible_user`` and ``ansible_password``
* Ensure that the user is a member of the local Administrators group or has been explicitly
- granted access (a connection test with the ``winrs`` command can be used to
+ granted access (a connection test with the ``winrs`` command can be used to
rule this out).
* Make sure that the authentication option set by ``ansible_winrm_transport`` is enabled under
@@ -438,7 +440,7 @@ Ansible is unable to reach the host. Some things to check for include:
* Make sure the firewall is not set to block the configured WinRM listener ports
* Ensure that a WinRM listener is enabled on the port and path set by the host vars
-* Ensure that the ``winrm`` service is running on the Windows host and configured for
+* Ensure that the ``winrm`` service is running on the Windows host and configured for
automatic start
Connection Refused Errors
@@ -455,13 +457,117 @@ Sometimes an installer may restart the WinRM or HTTP service and cause this erro
best way to deal with this is to use ``win_psexec`` from another
Windows host.
+Windows SSH Setup
+`````````````````
+Ansible 2.8 has added experimental support for using SSH to connect to a
+Windows host.
+
+.. warning::
+ Use this feature at your own risk!
+ Using SSH with Windows is experimental, the implementation may make
+ backwards incompatible changes in feature releases. The server side
+ components can be unreliable depending on the version that is installed.
+
+Installing Win32-OpenSSH
+------------------------
+The first step to using SSH with Windows is to install the `Win32-OpenSSH <https://github.com/PowerShell/Win32-OpenSSH>`_
+service on the Windows host. Microsoft offers a way to install ``Win32-OpenSSH`` through a Windows
+capability but currently the version that is installed through this process is
+too old to work with Ansible. To install ``Win32-OpenSSH`` for use with
+Ansible, select one of these three installation options:
+
+* Manually install the service, following the `install instructions <https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH>`_
+ from Microsoft.
+
+* Use ``win_chocolatey`` to install the service::
+
+ - name: install the Win32-OpenSSH service
+ win_chocolatey:
+ name: openssh
+ package_params: /SSHServerFeature
+ state: present
+
+* Use an existing Ansible Galaxy role like `jborean93.win_openssh <https://galaxy.ansible.com/jborean93/win_openssh>`_::
+
+ # Make sure the role has been downloaded first
+ ansible-galaxy install jborean93.win_openssh
+
+ # main.yml
+ - name: install Win32-OpenSSH service
+ hosts: windows
+ gather_facts: no
+ roles:
+ - role: jborean93.win_openssh
+ opt_openssh_setup_service: True
+
+.. note:: ``Win32-OpenSSH`` is still a beta product and is constantly
+ being updated to include new features and bugfixes. If you are using SSH as
+ a connection option for Windows, it is highly recommend you install the
+ latest release from one of the 3 methods above.
+
+Configuring the Win32-OpenSSH shell
+-----------------------------------
+
+By default ``Win32-OpenSSH`` will use ``cmd.exe`` as a shell. To configure a
+different shell, use an Ansible task to define the registry setting::
+
+ - name: set the default shell to PowerShell
+ win_regedit:
+ path: HKLM:\SOFTWARE\OpenSSH
+ name: DefaultShell
+ data: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
+ type: string
+ state: present
+
+ # Or revert the settings back to the default, cmd
+ - name: set the default shell to cmd
+ win_regedit:
+ path: HKLM:\SOFTWARE\OpenSSH
+ name: DefaultShell
+ state: absent
+
+Win32-OpenSSH Authentication
+----------------------------
+Win32-OpenSSH authentication with Windows is similar to SSH
+authentication on Unix/Linux hosts. You can use a plaintext password or
+SSH public key authentication, add public keys to an ``authorized_key`` file
+in the ``.ssh`` folder of the user's profile directory, and configure the
+service using the ``sshd_config`` file used by the SSH service as you would on
+a Unix/Linux host.
+
+When using SSH key authentication with Ansible, the remote session won't have access to the
+user's credentials and will fail when attempting to access a network resource.
+This is also known as the double-hop or credential delegation issue. There are
+two ways to work around this issue:
+
+* Use plaintext password auth by setting ``ansible_password``
+* Use ``become`` on the task with the credentials of the user that needs access to the remote resource
+
+Configuring Ansible for SSH on Windows
+--------------------------------------
+To configure Ansible to use SSH for Windows hosts, you must set two connection variables:
+
+* set ``ansible_connection`` to ``ssh``
+* set ``ansible_shell_type`` to ``cmd`` or ``powershell``
+
+The ``ansible_shell_type`` variable should reflect the ``DefaultShell``
+configured on the Windows host. Set to ``cmd`` for the default shell or set to
+``powershell`` if the ``DefaultShell`` has been changed to PowerShell.
+
+Known issues with SSH on Windows
+--------------------------------
+Using SSH with Windows is experimental, and we expect to uncover more issues.
+Here are the known ones:
+
+* Win32-OpenSSH versions older than ``v7.9.0.0p1-Beta`` do not work when ``powershell`` is the shell type
+* While SCP should work, SFTP is the recommended SSH file transfer mechanism to use when copying or fetching a file
+
+
.. seealso::
- :doc:`index`
- The documentation index
- :doc:`playbooks`
+ :ref:`about_playbooks`
An introduction to playbooks
- :doc:`playbooks_best_practices`
+ :ref:`playbooks_best_practices`
Best practices advice
:ref:`List of Windows Modules <windows_modules>`
Windows specific module list, all implemented in PowerShell