Kom*_*tel 1 loops file line-by-line ansible
我想创建一个剧本,将本地文件读取到 var,然后能够逐行循环遍历这个 var 并在任务中使用这些行。
要获取我使用的文件内容:
file_contents: "{{lookup('file', './myfile.txt')}}"
Run Code Online (Sandbox Code Playgroud)
我尝试使用:
但是我没有得到我想要的结果。
任何帮助,将不胜感激。
您可以对某些类型使用 Python 内置函数,例如字符串。
因此,这将为您解决问题:
file_contents_lines: "{{ lookup('file', './aaa.txt').splitlines() }}"
Run Code Online (Sandbox Code Playgroud)
和
with_items: "{{ file_contents_lines }}"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7068 次 |
| 最近记录: |