在Ansible中,可以使用stdin
模块向命令提供输入文件。下面是一个使用stdin
模块的示例:
- name: Run command with input file
hosts: localhost
tasks:
- name: Create input file
copy:
content: |
This is the input file content.
It can have multiple lines.
dest: /path/to/input.txt
- name: Run command with input file
shell: cat
args:
stdin: "{{ lookup('file', '/path/to/input.txt') }}"
在上面的示例中,首先使用copy
模块创建一个输入文件input.txt
,然后使用shell
模块运行cat
命令并将输入文件内容通过stdin
参数传递给命令。
注意,在实际使用中,应根据实际情况修改/path/to/input.txt
的路径和cat
命令为需要执行的命令。