virtualbox 中 Windows 8.1 VM 的 Packer ansible provisioner 问题
Issue with Packer ansible provisioner for Windows 8.1 VM in virtualbox
为了提供有关设置的一些上下文,我正在尝试从我的本地 Macbook 使用 VirtualBox 作为提供程序并使用 Ansible 作为配置程序启动一个 Windows 8.1 (x64) VM 和 Packer。我已经使用 Packer(没有 Ansible provisioner)测试了 Windows 构建,它运行成功。
但是,当我尝试使用 ansible provisioner(不是 ansible-local)时,我无法这样做。我已经按照 ansible 的 packer 文档中指定的方式设置了 Packer 构建:https://www.packer.io/docs/provisioners/ansible.html。
我还 运行 ConfigureRemotingForAnsible。ps1 在 Windows VM 首次启动时在 http://docs.ansible.com/ansible/intro_windows.html#windows-system-prep 中提到。
我的技术堆栈版本是:
- Packer 1.0.0
- Ansible 2.3.0.0
- Python 2.7.11
- pywinrm 0.2.2
- VirtualBox 5.1.20
packer.json文件如下
{
"builders": [
{
"type": "virtualbox-iso",
"iso_url": "{{ user `iso_url` }}",
"iso_checksum_type": "sha1",
"iso_checksum": "{{ user `iso_checksum` }}",
"communicator": "winrm",
"headless": "{{ user `headless` }}",
"boot_wait": "9m",
"winrm_use_ssl": true,
"winrm_insecure": true,
"winrm_host": "127.0.0.1",
"winrm_port": 5986,
"winrm_username": "packer",
"winrm_password": "packer",
"winrm_timeout": "8h",
"shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
"guest_os_type": "Windows81_64",
"guest_additions_mode": "disable",
"floppy_files": [
"./answer_files/81/Autounattend.xml",
"./scripts/enable-winrm.ps1",
"./scripts/ConfigureRemotingForAnsible.ps1"
],
"vboxmanage": [
[ "modifyvm", "{{.Name}}", "--natpf1", "winrm,tcp,,5986,,5986" ],
[ "modifyvm", "{{.Name}}", "--memory", "4096" ],
[ "modifyvm", "{{.Name}}", "--vram", "32" ],
[ "modifyvm", "{{.Name}}", "--cpus", "2" ]
]
}
],
"provisioners": [
{
"type": "ansible",
"playbook_file": "./provisioner/run-powershell.yml",
"local_port": "5986",
"user": "packer",
"extra_arguments": [
"-vvvv",
"--connection", "packer",
"--extra-vars", "ansible_shell_type=powershell ansible_shell_executable=None"
]
}
],
"post-processors": [
{
"type": "vagrant",
"keep_input_artifact": true,
"output": "output-formats/windows_81_{{.Provider}}.box",
"vagrantfile_template": "vagrantfile-windows_81.template"
}
],
"variables": {
"headless": "false",
"iso_checksum": "CHECKSUM_VALUE",
"iso_url": "/path/to/iso"
}
}
运行-powershell.yml 剧本是:
# This playbook tests the script module on Windows hosts
- name: Run Ansible play
hosts: all
gather_facts: no
tasks:
- name: Ping windows machine
win_command: cmd.exe /c powershell -Command "Write-Host 'Hello World!'"
# - name: Ping windows machine
# win_ping:
# - name: Create a file
# win_file:
# path: "C:\Windows\Temp\ansible_test.txt"
# state: touch
# - name: Run powershell script
# script: a:\helloworld.ps1
在 packer.log 中看到的错误的最后片段是:
ui: [0;32m virtualbox-iso: <127.0.0.1> (1, '{"exception":"At C:\\Users\\packer\\AppData\\Local\\Temp\\ansible-tmp-1493195766.64-166408222728325\\win_command.ps1:25 char:16\r\n+ $parsed_args = Parse-Args $args $false\r\n+ ~~~~~~~~~~","msg":"The term \u0027Parse-Args\u0027 is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.","failed":true}\r\n', 'OpenSSH_6.9p1, LibreSSL 2.1.8\r\ndebug1: Reading configuration data /Users/mk/.ssh/config\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 7498\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\nShared connection to 127.0.0.1 closed.\r\n')[0m
ui: [0;32m virtualbox-iso: The full traceback is:[0m
ui: [0;32m virtualbox-iso: At C:\Users\packer\AppData\Local\Temp\ansible-tmp-1493195766.64-166408222728325\win_command.ps1:25 char:16[0m
ui: [0;32m virtualbox-iso: + $parsed_args = Parse-Args $args $false[0m
ui: [0;32m virtualbox-iso: + ~~~~~~~~~~[0m
ui: [0;32m virtualbox-iso: fatal: [default]: FAILED! => {[0m
ui: [0;32m virtualbox-iso: "changed": false,[0m
ui: [0;32m virtualbox-iso: "failed": true,[0m
ui: [0;32m virtualbox-iso: "msg": "The term 'Parse-Args' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."[0m
ui: [0;32m virtualbox-iso: }[0m
ui: [0;32m virtualbox-iso: to retry, use: --limit @/Users/mk/Workspace/packer/win81/provisioner/run-powershell.retry[0m
ui: [0;32m virtualbox-iso:[0m
ui: [0;32m virtualbox-iso: PLAY RECAP *********************************************************************[0m
ui: [0;32m virtualbox-iso: default : ok=0 changed=0 unreachable=0 failed=1[0m
ui: [0;32m virtualbox-iso:[0m
packer: 2017/04/26 18:36:31 shutting down the SSH proxy
packer: 2017/04/26 18:36:31 Executing VBoxManage: []string{"controlvm", "packer-virtualbox-iso-1493195197", "poweroff"}
None ansible windows 任务(在 Windows VM 上作为 .ps1 执行)能够执行,并收到与上述相同的错误(请参阅我的剧本中的注释行)。它们在 Parse-Args cmdlet 上都是错误的,这是一个标准的 Powershell 函数,但由于某种原因在 Windows 8.1 vm 上无法识别。
仅供参考:我还在端口 5985(没有 SSL)上尝试了 运行ning winrm,但得到了同样的错误。
我们将不胜感激解决此问题的任何帮助。
遇到了同样的问题。我发现最近版本的 Ansible 有问题。我将我的 Ansible 安装降级到 2.2.0,它按照 Packer 文档的预期工作。
为了提供有关设置的一些上下文,我正在尝试从我的本地 Macbook 使用 VirtualBox 作为提供程序并使用 Ansible 作为配置程序启动一个 Windows 8.1 (x64) VM 和 Packer。我已经使用 Packer(没有 Ansible provisioner)测试了 Windows 构建,它运行成功。
但是,当我尝试使用 ansible provisioner(不是 ansible-local)时,我无法这样做。我已经按照 ansible 的 packer 文档中指定的方式设置了 Packer 构建:https://www.packer.io/docs/provisioners/ansible.html。 我还 运行 ConfigureRemotingForAnsible。ps1 在 Windows VM 首次启动时在 http://docs.ansible.com/ansible/intro_windows.html#windows-system-prep 中提到。
我的技术堆栈版本是:
- Packer 1.0.0
- Ansible 2.3.0.0
- Python 2.7.11
- pywinrm 0.2.2
- VirtualBox 5.1.20
packer.json文件如下
{
"builders": [
{
"type": "virtualbox-iso",
"iso_url": "{{ user `iso_url` }}",
"iso_checksum_type": "sha1",
"iso_checksum": "{{ user `iso_checksum` }}",
"communicator": "winrm",
"headless": "{{ user `headless` }}",
"boot_wait": "9m",
"winrm_use_ssl": true,
"winrm_insecure": true,
"winrm_host": "127.0.0.1",
"winrm_port": 5986,
"winrm_username": "packer",
"winrm_password": "packer",
"winrm_timeout": "8h",
"shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
"guest_os_type": "Windows81_64",
"guest_additions_mode": "disable",
"floppy_files": [
"./answer_files/81/Autounattend.xml",
"./scripts/enable-winrm.ps1",
"./scripts/ConfigureRemotingForAnsible.ps1"
],
"vboxmanage": [
[ "modifyvm", "{{.Name}}", "--natpf1", "winrm,tcp,,5986,,5986" ],
[ "modifyvm", "{{.Name}}", "--memory", "4096" ],
[ "modifyvm", "{{.Name}}", "--vram", "32" ],
[ "modifyvm", "{{.Name}}", "--cpus", "2" ]
]
}
],
"provisioners": [
{
"type": "ansible",
"playbook_file": "./provisioner/run-powershell.yml",
"local_port": "5986",
"user": "packer",
"extra_arguments": [
"-vvvv",
"--connection", "packer",
"--extra-vars", "ansible_shell_type=powershell ansible_shell_executable=None"
]
}
],
"post-processors": [
{
"type": "vagrant",
"keep_input_artifact": true,
"output": "output-formats/windows_81_{{.Provider}}.box",
"vagrantfile_template": "vagrantfile-windows_81.template"
}
],
"variables": {
"headless": "false",
"iso_checksum": "CHECKSUM_VALUE",
"iso_url": "/path/to/iso"
}
}
运行-powershell.yml 剧本是:
# This playbook tests the script module on Windows hosts
- name: Run Ansible play
hosts: all
gather_facts: no
tasks:
- name: Ping windows machine
win_command: cmd.exe /c powershell -Command "Write-Host 'Hello World!'"
# - name: Ping windows machine
# win_ping:
# - name: Create a file
# win_file:
# path: "C:\Windows\Temp\ansible_test.txt"
# state: touch
# - name: Run powershell script
# script: a:\helloworld.ps1
在 packer.log 中看到的错误的最后片段是:
ui: [0;32m virtualbox-iso: <127.0.0.1> (1, '{"exception":"At C:\\Users\\packer\\AppData\\Local\\Temp\\ansible-tmp-1493195766.64-166408222728325\\win_command.ps1:25 char:16\r\n+ $parsed_args = Parse-Args $args $false\r\n+ ~~~~~~~~~~","msg":"The term \u0027Parse-Args\u0027 is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.","failed":true}\r\n', 'OpenSSH_6.9p1, LibreSSL 2.1.8\r\ndebug1: Reading configuration data /Users/mk/.ssh/config\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 7498\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\nShared connection to 127.0.0.1 closed.\r\n')[0m
ui: [0;32m virtualbox-iso: The full traceback is:[0m
ui: [0;32m virtualbox-iso: At C:\Users\packer\AppData\Local\Temp\ansible-tmp-1493195766.64-166408222728325\win_command.ps1:25 char:16[0m
ui: [0;32m virtualbox-iso: + $parsed_args = Parse-Args $args $false[0m
ui: [0;32m virtualbox-iso: + ~~~~~~~~~~[0m
ui: [0;32m virtualbox-iso: fatal: [default]: FAILED! => {[0m
ui: [0;32m virtualbox-iso: "changed": false,[0m
ui: [0;32m virtualbox-iso: "failed": true,[0m
ui: [0;32m virtualbox-iso: "msg": "The term 'Parse-Args' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."[0m
ui: [0;32m virtualbox-iso: }[0m
ui: [0;32m virtualbox-iso: to retry, use: --limit @/Users/mk/Workspace/packer/win81/provisioner/run-powershell.retry[0m
ui: [0;32m virtualbox-iso:[0m
ui: [0;32m virtualbox-iso: PLAY RECAP *********************************************************************[0m
ui: [0;32m virtualbox-iso: default : ok=0 changed=0 unreachable=0 failed=1[0m
ui: [0;32m virtualbox-iso:[0m
packer: 2017/04/26 18:36:31 shutting down the SSH proxy
packer: 2017/04/26 18:36:31 Executing VBoxManage: []string{"controlvm", "packer-virtualbox-iso-1493195197", "poweroff"}
None ansible windows 任务(在 Windows VM 上作为 .ps1 执行)能够执行,并收到与上述相同的错误(请参阅我的剧本中的注释行)。它们在 Parse-Args cmdlet 上都是错误的,这是一个标准的 Powershell 函数,但由于某种原因在 Windows 8.1 vm 上无法识别。
仅供参考:我还在端口 5985(没有 SSL)上尝试了 运行ning winrm,但得到了同样的错误。
我们将不胜感激解决此问题的任何帮助。
遇到了同样的问题。我发现最近版本的 Ansible 有问题。我将我的 Ansible 安装降级到 2.2.0,它按照 Packer 文档的预期工作。