Install Docker on Windows Server 2016 using win_shell module

1,429 views
Skip to first unread message

Pasquale Carlo Maiorano Picone

unread,
Jul 17, 2017, 5:51:06 PM7/17/17
to Ansible Project
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        

                                                                                                          


J Hawkesworth

unread,
Jul 25, 2017, 1:36:45 AM7/25/17
to Ansible Project
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

Yuriy Ostapenko

unread,
Jul 31, 2017, 8:14:21 AM7/31/17
to Ansible Project
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.

Jordan Borean

unread,
Aug 1, 2017, 4:45:55 AM8/1/17
to Ansible Project
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.

Yuriy Ostapenko

unread,
Aug 1, 2017, 7:00:57 AM8/1/17
to Ansible Project
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.

Andreas Mosti

unread,
Jan 18, 2018, 5:29:15 AM1/18/18
to Ansible Project
Can you paste the Ansible-tasks you got working? Seeing the same issues here..

Larry Smith

unread,
Jan 19, 2018, 1:10:24 AM1/19/18
to Ansible Project
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.

Andreas Mosti

unread,
Jan 19, 2018, 3:02:54 AM1/19/18
to Ansible Project
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.

Larry Smith

unread,
Jan 19, 2018, 8:22:05 AM1/19/18
to Ansible Project
Awesome. Glad you got it sorted out.
Reply all
Reply to author
Forward
0 new messages