ansible - 在 Ansible 中读取 Windows 主机上的文件
问题描述
与 PowerShell中的命令类似Get-Content
,我正在寻找一种方法来读取 Windows 目标上的文件并将文件内容保存到 Ansible 中的变量中。文档说该ansible.builtin.file
模块能够获取文件内容,但该功能似乎不适用于该win_file
模块。
以下伪代码应该更好地解释我正在尝试做的事情:
- name: save file contents to variable
win_get_content:
path: C:\somefile.txt
register: file_contents
解决方案
如果"{{lookup('file', 'C:\somefile.txt') }}"在窗口中不起作用,您可以尝试:
- name: get content of file
win_shell: 'type C:\somefile.txt'
register: file_contents
- name: display content
debug:
msg: "{{ file_contents.stdout_lines }} "
推荐阅读
- mysql - 用最高记录按子句分组 - MYsql
- c - 不使用 printf 打印新行
- html - 在此全屏视频下制作文字
- html - 在文件目录中搜索匹配字符串,找到时将指定文本附加到末尾
- c - 为什么 C 中结构的大小在通过引用传递时会增加
- c# - 如何从 ac# 控制台应用程序启用 UI 调用?使用 PowerShell 获取凭据
- python - 保持图例远离数据点 matplotlib
- reactjs - 如何将 redux-persist 与自定义中间件一起使用
- node.js - Uncaught SyntaxError: Unexpected token < while deploying to Heroku
- ruby - 捆绑安装失败,Gem 安装成功