无法查看 Ansible 受管节点中的文件内容
Unable to view the contents of file in ansible managed nodes
我正在尝试从托管节点和控制节点查看文件的内容,在这里我看到语法适用于本地主机 (172.17.254.200) 但不适用于远程主机。以下是我使用查找/查询插件编写的任务,能否请您提出修复建议:
---
- name: Report Test
hosts: all
roles:
- patching
tasks:
- name: Display the Pre and Post check Differences
debug:
msg: "{{ query('file', '/tmp/check/{{ inventory_hostname }}_Comparison') }}"
下面是输出
TASK [patching : Display the Pre and Post check Differences] ***********************************************************************************************************
ok: [172.17.254.200] =>
msg:
- |-
free_m - YES
sysctl_all - YES
uptime - YES
[WARNING]: Unable to find '/tmp/check/172.17.254.207_Comparison' in expected paths (use -vvvvv to see paths)
fatal: [172.17.254.207]: FAILED! =>
msg: 'An unhandled exception occurred while running the lookup plugin ''file''. Error was a <class ''ansible.errors.AnsibleError''>, original message: could not locate file in lookup: /tmp/check/172.17.254.207_Comparison'
[WARNING]: Unable to find '/tmp/check/172.17.254.208_Comparison' in expected paths (use -vvvvv to see paths)
fatal: [172.17.254.208]: FAILED! =>
msg: 'An unhandled exception occurred while running the lookup plugin ''file''. Error was a <class ''ansible.errors.AnsibleError''>, original message: could not locate file in lookup: /tmp/check/172.17.254.208_Comparison'
lookup 和 query ”在 Ansible 控制机器上执行和评估。”
使用slurp。引用:
This module returns an ‘in memory’ base64 encoded version of the file, take into account that this will require at least twice the RAM as the original file size.
对于较大的文件使用 fetch。引用:
It is used for fetching files from remote machines and storing them locally in a file tree, organized by hostname.
查找在 Ansible 控制器上执行(正如@Vladimir Botka 所指出的)。如果你只是想查看远程主机上文件的内容,你可以cat
通过ansible文件并调试stdout_lines
.
- command: "cat /tmp/check/{{ inventory_hostname }}_Comparison"
register: file_cat
changed_when: false
- debug:
var: file_cat.stdout_lines
我正在尝试从托管节点和控制节点查看文件的内容,在这里我看到语法适用于本地主机 (172.17.254.200) 但不适用于远程主机。以下是我使用查找/查询插件编写的任务,能否请您提出修复建议:
---
- name: Report Test
hosts: all
roles:
- patching
tasks:
- name: Display the Pre and Post check Differences
debug:
msg: "{{ query('file', '/tmp/check/{{ inventory_hostname }}_Comparison') }}"
下面是输出
TASK [patching : Display the Pre and Post check Differences] ***********************************************************************************************************
ok: [172.17.254.200] =>
msg:
- |-
free_m - YES
sysctl_all - YES
uptime - YES
[WARNING]: Unable to find '/tmp/check/172.17.254.207_Comparison' in expected paths (use -vvvvv to see paths)
fatal: [172.17.254.207]: FAILED! =>
msg: 'An unhandled exception occurred while running the lookup plugin ''file''. Error was a <class ''ansible.errors.AnsibleError''>, original message: could not locate file in lookup: /tmp/check/172.17.254.207_Comparison'
[WARNING]: Unable to find '/tmp/check/172.17.254.208_Comparison' in expected paths (use -vvvvv to see paths)
fatal: [172.17.254.208]: FAILED! =>
msg: 'An unhandled exception occurred while running the lookup plugin ''file''. Error was a <class ''ansible.errors.AnsibleError''>, original message: could not locate file in lookup: /tmp/check/172.17.254.208_Comparison'
lookup 和 query ”在 Ansible 控制机器上执行和评估。”
使用slurp。引用:
This module returns an ‘in memory’ base64 encoded version of the file, take into account that this will require at least twice the RAM as the original file size.
对于较大的文件使用 fetch。引用:
It is used for fetching files from remote machines and storing them locally in a file tree, organized by hostname.
查找在 Ansible 控制器上执行(正如@Vladimir Botka 所指出的)。如果你只是想查看远程主机上文件的内容,你可以cat
通过ansible文件并调试stdout_lines
.
- command: "cat /tmp/check/{{ inventory_hostname }}_Comparison"
register: file_cat
changed_when: false
- debug:
var: file_cat.stdout_lines