ansible - 如何对同一目录中的多个文件执行 dos2unix 命令?
问题描述
我试过-name: convert files to Unix format command: dos2unix "{{ scripts_dir }}/*.sh"</p>
它说dos2unix:转换文件时出现问题。完全相同的命令在 shell 中工作。我只想知道是否有更快的方法而不是使用循环(with_items 或 with_fileglob)。
命令:dos2unix “{{ item }}” with_fileglob: - “{{ scripts_dir }}/*.sh”</p>
以上是我拥有的当前工作版本。
解决方案
通过使用“命令”,您只需执行一个命令。但是您正在使用通配符(*)。这是由一个shell 完成的,即bash。所以你应该使用 shell 模块:
- name: Execute dos2unix on several files
shell: dos2unix “{{ scripts_dir }}/*.sh"
args:
chdir: "/home/yourdir/"
推荐阅读
- java - 使用正则表达式将句子拆分为标记,去除所有必要的标点符号,不包括作为单词一部分的标点符号
- r - 如何删除要像 png 一样导出的 data.frame 中的行名?
- excel - 如何修复我的 VBA 代码,使电子邮件内容中的日期不是静态的
- linux - 带有括号的 Bash for 循环在 linux 中工作,而不是在 Git Bash 中
- spring-boot - 在 prometheus 集成中添加端点
- c# - Console.Clear() 停止方法执行(未达到 IOException)
- javascript - 从html调用JS文件
- git - 如何可视化git(拓扑)中的分支,其中 git log --graph 不显示它们?
- npm - Gulp 本地和 CLI 版本在全局和项目文件夹内不匹配
- excel - Excel自己的函数:编译错误:未定义子或函数