我正试图从Ansible运行此PowerShell命令,但执行时出现错误"表达式或语句"中出现意外的标记":";因为寄存器没有以正确的格式打印:{'msg':'Postman_qyy7z89j1cgve','failed':False,'changed':False}。
行动手册:
- hosts: localhost
connection: local
vars:
subscription_id: ""
workspace_name: "WVD-WorkSpace"
hostpool_name: "WVD-HostPool"
rg_name: "WVD"
uri_path: '\certsignMSIXAppAttach_StorePostman_8.0.7.0_x64.vhdx'
DisplayName: "postman"
appgroup_name: "WVD-DesktopAG"
tasks:
- name: Get Package App id
shell: |
$obj = Expand-AzWvdMsixImage -HostPoolName {{ hostpool_name }} -ResourceGroupName {{ rg_name }} -SubscriptionId {{ subscription_id }} -Uri {{ uri_path }}
Write-Output $obj.PackageApplication.AppId
args:
executable: /usr/local/bin/pwsh
register: packageappid
- name: Get PackageFamilyName
shell: |
$obj = Expand-AzWvdMsixImage -HostPoolName {{ hostpool_name }} -ResourceGroupName {{ rg_name }} -SubscriptionId {{ subscription_id }} -Uri {{ uri_path }}
Write-Output $obj.PackageFamilyName > PackageFamilyName
args:
executable: /usr/local/bin/pwsh
- name: echo Package Family Name
debug:
msg: "{{ lookup('file', 'packagefamilyname') | regex_replace('"', " ")}}"
register: packagefamilyname
- debug:
var: packagefamilyname
- name: Add MSIX Package to HostPool
shell: New-AzWvdMsixPackage -HostPoolName {{ hostpool_name }} -ResourceGroupName {{ rg_name }} -SubscriptionId {{ subscription_id }} -PackageAlias {{ DisplayName }} -DisplayName {{ DisplayName }} -ImagePath {{ uri_path }} -IsActive:$true
args:
executable: /usr/local/bin/pwsh
- name: Add MSIX Package to App group
shell: New-AzWvdApplication -ResourceGroupName {{ rg_name }} -SubscriptionId {{ subscription_id }} -Name Postman -ApplicationType MsixApplication -ApplicationGroupName {{ appgroup_name }} -MsixPackageFamilyName {{ packagefamilyname }} -CommandLineSetting 0
args:
executable: /usr/local/bin/pwsh
获取此错误:
fatal: [localhost]: FAILED! => {"changed": true, "cmd": "New-AzWvdApplication -ResourceGroupName WVD -SubscriptionId xxxxxxxxxxxxxxx -Name Postman -ApplicationType MsixApplication -ApplicationGroupName WVD-DesktopAG -MsixPackageFamilyName {'msg': 'Postman_qyy7z89j1cgve', 'failed': False, 'changed': False} -CommandLineSetting 0", "delta": "0:00:00.454569", "end": "2021-04-29 15:38:29.238059", "msg": "non-zero return code", "rc": 1, "start": "2021-04-29 15:38:28.783490", "stderr": "u001b[91mParserError: nu001b[96mLine |nu001b[96m 1 | u001b[0m … icationGroupName WVD-DesktopAG -MsixPackageFamilyName {'msg'u001b[96m:u001b[0m 'Postma …nu001b[96m | u001b[91m ~nu001b[91mu001b[96m | u001b[91mUnexpected token ':' in expression or statement.nu001b[0m", "stderr_lines": ["u001b[91mParserError: ", "u001b[96mLine |", "u001b[96m 1 | u001b[0m … icationGroupName WVD-DesktopAG -MsixPackageFamilyName {'msg'u001b[96m:u001b[0m 'Postma …", "u001b[96m | u001b[91m ~", "u001b[91mu001b[96m | u001b[91mUnexpected token ':' in expression or statement.", "u001b[0m"], "stdout": "", "stdout_lines": []}
您永远不应该(?(register:
debug:
任务,因为这几乎肯定不是您真正想要的。也就是说,这个信息非常清楚,并且与其他register:
行为一致:它是dict
,你把它当作str
来对待,所以把{{ packagefamilyname }}
改成{{ packagefamilyname.msg }}
,希望你不要在一个团队中工作,在这个团队中,一些可怜的人不得不想知道为什么会存在这种模式