ansible - 我需要使用 ansible 以下命令执行: FOR /f "skip=7 delims=" %%a IN (' DIR D:\backups\auto\ /od /b') DO RD /S /Q "D:\backups \自动\%%a"
问题描述
我需要使用 ansible 以下命令执行:
FOR /f "skip=7 delims=" %%a IN (' DIR D:\backups\auto\ /o-d /b') DO RD /S /Q "D:\backups\auto\%%a"
试过这个:
- name: clear old backups
win_command:
FOR /f "skip=7 delims=" %%a IN (' DIR D:\backups\auto\ /o-d /b') DO RD /S /Q "D:\backups\auto\%%a"
解决方案
虽然win_command:
文档对这一事实保持沉默,但根据阅读win_shell:
文档显示 PowerShell.exe 是默认值,而不是 CMD.exe
在文档中,它说您可以通过在任务中win_shell:
指定来明确选择使用 CMD.exe 而不是 powershell :executable: cmd.exe
args:
- name: clear old backups
win_shell:
FOR /f "skip=7 delims=" %%a IN (' DIR D:\backups\auto\ /o-d /b') DO RD /S /Q "D:\backups\auto\%%a"
args:
executable: cmd.exe
win_command:
出于不允许 shell 运算符的相同原因,必须使用win_shell:
才能访问 shell 内置函数,例如FOR
和IF
表达式
推荐阅读
- r - 如何将函数应用于 data.frame 中的多个类别?
- c# - 在构造对象实例时,分离 DI 和数据参数的有效方法是什么?
- file - 尝试从最终来自 S3 存储桶的资源下载时,Scrapy 返回 empy 文件下载结果
- c++ - 将 MariaDB 设置为 CentOS7 服务的问题
- flutter - 为什么克隆时的项目结构像这样颤动?
- python - 如何将 dlib 安装到我的树莓派 3?
- c++ - 无法使用控制台在 CLion 中执行 .cpp 文件并执行命令(Windows 10)
- python - 如何获取包含值列表的列名?
- django - Django,表单提交错误,Django 表单无法输入文本
- php - 获取每个用户 eloquent laravel 的每个事件类型的最新行