首页 > 解决方案 > 使用 Ansible 在 Windows 10 VM 中安装和配置 docker 桌面

问题描述

我正在尝试使用 Ansible 在 Windows 10 VM 中安装 Docker Desktop。但是我不能使用ansible来做到这一点。我尝试使用 powershell 脚本来运行 Docker Desktop.exe

#requires -RunAsAdministrator
#requires -Version 5.1

$ErrorActionPreference = "Stop"

Start-Process Docker` Desktop.exe` -WorkingDirectory C:\Program` Files\Docker\Docker`

如果我在 windows powershell 中运行这个脚本,它工作正常。如果我使用 ansible 运行它,它不起作用。

---
# tasks file for install_docker_windows

# Waiting for 900 seconds to reach windows machine over WinRM
- name: Wait for system to become reachable over WinRM
  wait_for_connection:
    timeout: 900

# Gather facts about the host (windows machine)
- name: Gather facts for first time
  setup:

# Docker is by default installed in case of windows VM, but its need to started.

# Downloading wsl2 linux kernel update package to C:\ drive
- name: Download WSL2 linux kernel update package
  win_get_url:
    url: 'https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi'
    dest: 'c:\wsl_update_x64.msi'

# Installing the downloaded wsl2 linux kernel update package from C:\wsl_update_x64.msi path
- name: Install WSL2 linux kernel update package
  win_package:
    path: 'c:\wsl_update_x64.msi'

# Starting docker desktop.exe in async mode
- name: Run docker
  ansible.windows.win_powershell:
    script: |
      & cd "C:\Program Files\Docker\Docker"
      $proc = Start-Process -FilePath ".\Docker Desktop.exe" -PassThru -Wait
      $proc.WaitForExit()
      & 'C:\Program Files\Docker\Docker\DockerCli.exe' -SwitchDaemon
    error_action: stop
  async: 180
  poll: 0
  register: docker_run

# Wait for docker ps to be running
- name: Check docker running
  become: true
  become_method: runas
  become_user: quarticadmin
  ansible.windows.win_shell: docker ps
  register: docker_running
  retries: 80
  delay: 10
  until: docker_running.stdout is match("CONTAINER*")

现在我正在尝试使用上面的 ansible playbook。如果我在运行 ansible playbook 之前使用 Microsoft 远程桌面连接打开 VM,它就可以工作。

请有人帮我做到这一点我找不到可行的解决方案如何在不打开 VM 的情况下使用 ansible 运行 docker 桌面。

谢谢

标签: windowsansibledocker-desktop

解决方案


推荐阅读