windows - 使用 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 桌面。
谢谢
解决方案
推荐阅读
- php - 数组推送到对象数组
- azure-ad-b2c - 登录回调失败 w/500,如何调试原因
- python-3.x - 为什么这两个代码的输出不同?
- php - Laravel 通过 API 上传图片
- python - Python - pydriosm - Import - OSError: [WinError 126] 找不到指定的模块
- c++ - 如何在 cUrl C++ 中实现 Ftp Get in Memory 功能?
- java - 在 SWT eclipse 插件上更新用户界面的最佳技术
- python - 为什么flask_wtf.FlaskForm 上传文件会报错,说文件没有上传?
- javascript - 具有返回值的函数的数组
- c# - 如何使用实体框架处理表单数据并提取两个不同模型/表的属性