Install Docker on Windows Server 2016 using win_shell module

ISSUE TYPE

  • Bug Report

COMPONENT NAME
Win_shell

ANSIBLE VERSION

ansible 2.3.0.0 config file = /home/<my-user>/ansible-docker/ansible.cfg (just disabled host key checking) configured module search path = Default w/o overrides python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]

CONFIGURATION

`
host_key_checking = False

`

OS / ENVIRONMENT
Control Machine: Ubuntu 16.04 machine
Guest Machine: Windows Server 2016

SUMMARY

Could not install Docker for Windows using the same commands indicated on docker interactive installation on docker website(https://docs.docker.com/engine/installation/windows/docker-ee/).

STEPS TO REPRODUCE

Windows Server 2016, clean installation with Powershell Remoting and WinRM service enabled with basic authentication and allow unencrypted for WinRM service.

`

  • hosts: windows
    tasks:
  • name: Enable Windows Container Feature
    win_feature:
    name: Containers
    state: present
  • name: Install Nuget Package Provider
    win_shell: Install-PackageProvider -Name “NuGet” -MinimumVersion “2.8.5.201” -Force
  • name: Install Docker Msft Module
    win_shell: Install-Module -Name “DockerMsftProvider” -Repository “PSGallery” -Force
  • name: Install Docker package error in this task
    win_shell: Install-Package –ProviderName “DockerMsftProvider” -Name “Docker” -Force
  • name: Start docker service #Start-Service docker
    win_service:
    name: docker
    state: started
    start_mode: auto
    `

EXPECTED RESULTS
Docker installed and running

ACTUAL RESULTS
Package manager returns an error (see stacktrace below, refered to task for installation of Docker package)

TASK [Install Docker package] **************************************************************************************************************************************************************************** task path: /home/carlo/ansible-docker-trystack/windows_hosts.yml:11 Using module file /usr/lib/python2.7/dist-packages/ansible/modules/windows/win_shell.ps1 <192.168.87.129> ESTABLISH WINRM CONNECTION FOR USER: Administrator on PORT 5985 TO 192.168.87.129 EXEC (via pipeline wrapper) fatal: [192.168.87.129]: FAILED! => { "changed": true, "cmd": "Install-Package –ProviderName \"DockerMsftProvider\" -Name \"Docker\" -Force", "delta": "0:00:07.845040", "end": "2017-07-17 02:53:56.827786", "failed": true, "rc": 1, "start": "2017-07-17 02:53:48.982746", "stderr": "Install-Package : No match was found for the specified search criteria and package name 'Docker'. Try \r\nGet-PackageSource to see all available registered package sources.\r\nAt line:1 c har:65\r\n+ ... ing $false; Install-Package –ProviderName \"DockerMsftProvider\" -Name ...\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n + CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex \r\n ception\r\n + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement. Cmdlets.InstallPackage", "stderr_lines": [ "Install-Package : No match was found for the specified search criteria and package name 'Docker'. Try ", "Get-PackageSource to see all available registered package sources.", "At line:1 char:65", "+ ... ing $false; Install-Package –ProviderName \"DockerMsftProvider\" -Name ...", "+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~", " + CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex ", " ception", " + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage" ], "stdout": "", "stdout_lines": [] } to retry, use: --limit @/home/carlo/ansible-docker-trystack/windows_hosts.retry

Hi,

I am curious if you got any further with this.

I looked at the link above but couldn’t see any powershell command like you show to install docker. It looks like there is a .msi installer now, which I would hope could be installed using the win_package module.

The .msi installer is described on this page

https://docs.docker.com/docker-for-windows/install/#install-docker-for-windows

Hi,

I experienced the same issue.
Install-Package works from both local powershell session or remote with “Enter-PSSession”, but not from Ansible.

Apparently it has something to do with how Ansible does winrm and BITS.
Try switching to DockerMsftProviderInsider. It worked for me.

Similar issue with packer: https://github.com/StefanScherer/packer-windows/pull/33

It's interesting that is worked over a PSSession but still failed with Ansible. PSSession is run over WinRM which is the same protocol Ansible uses so if it didn't fail there there must be something else going on.

Strange indeed.

At least one difference would be that PSSession sends encrypted winrm payload over http, while ansible runs unencrypted winrm over https port, afaik.

Can you paste the Ansible-tasks you got working? Seeing the same issues here…

mandag 31. juli 2017 14.14.21 UTC+2 skrev Yuriy Ostapenko følgende:

Not sure if this will help you or not but you might be able to get some ideas from my Ansible role for Windows Docker installation.

https://github.com/mrlesmithjr/ansible-windows-docker

I got it working from the powershell-module with the following tasks:

  • name: Enable Windows Container Feature
    win_feature:
    name: Containers
    state: present
    register: dockerwindowsfeature

  • name: Reboot server if Windows Container Feature requires it
    win_reboot:
    when: dockerwindowsfeature.reboot_required

  • name: Add DockerMsftProviderInsider powershell module repository
    win_psmodule:
    name: DockerMsftProviderInsider
    state: present

  • name: Install Docker package
    win_shell: Install-Package –ProviderName “DockerMsftProviderInsider” -Name “Docker” -Force
    args:
    creates: “C:\Program Files\Docker\metadata.json”
    register: dockerinstall

  • name: Reboot server if Docker package requires it
    win_reboot:
    when: dockerinstall.changed

Might help somebody out.

fredag 19. januar 2018 07.10.24 UTC+1 skrev Larry Smith følgende:

Awesome. Glad you got it sorted out.