下面是我的 ansible 脚本 -
- name: To delete files
hosts: current
gather_facts: true
tasks:
- name: Check for the right folder
win_shell: |
if (Test-Path -Path 'C:\Program Files (x86)\MF\LGG\bin') {
Write-Output "LGG"
setx PATH "$env:path;C:\Program Files (x86)\MF\LGG\bin" -m
}
else {
Write-Output "LRR"
setx PATH "$env:path;C:\Program Files (x86)\MF\LRR\bin" -m
}
register: actualpath
- name: print output
debug:
msg: "output is {{ actualpath.stdout_lines }} "
- debug: var=actualpath.stdout
我的计划是捕获上面给出的输出并根据输出运行另一组命令,即LRR or LGG
但是当我尝试打印输出时,我看到它有不同的格式,如下所示 -
TASK [print output] ************************************************************
ok: [xxx] => {
"msg": "output is [u'LGG', u'', u'SUCCESS: Specified value was saved.'] "
}
TASK [debug] *******************************************************************
ok: [xxx] => {
"actualpath.stdout": "LGG\r\n\r\nSUCCESS: Specified value was saved.\r\n"
}
如何确保我只得到我正在打印的内容或如何修剪值并将其保存在寄存器中?