ansible 获取读取文件并将结果存储到变量
在Ansible中,可以使用ansible.builtin.shell模块和register关键字来读取文件,并将结果存储到变量中。以下是一个使用示例:
- name: 读取文件
hosts: all
tasks:
- name: 读取文件内容
ansible.builtin.shell: cat /path/to/file.txt
register: file_content
- name: 打印文件内容
ansible.builtin.debug:
var: file_content.stdout
在上述示例中,ansible.builtin.shell模块用于执行cat命令,读取/path/to/file.txt文件的内容,并将结果存储到file_content变量中。然后使用ansible.builtin.debug模块打印file_content.stdout变量的值,即文件的内容。
你可以根据需要修改/path/to/file.txt为你想要读取的文件路径
原文地址: https://www.cveoy.top/t/topic/ibBL 著作权归作者所有。请勿转载和采集!