Ansible:读取远程文件 [英] Ansible: read remote file
问题描述
我在远程主机上生成带有ansible的文件,并且在此生成之后,我想在另一个任务中读取这些文件.
I generate files with ansible on remote host and after this generation, I would like to read theses files in another task.
我找不到任何模块来读取带有ansible的远程文件(查找似乎仅在本地主机上).
I don't find any module to read remote file with ansible (lookup seems only on local host).
您知道这样的模块吗?
谢谢
这是我的用例:
我生成ssh密钥,并将其添加到github.这些键是由var文件中的对象设置的,因此我像这样循环生成它:
I generate ssh keys and I add it to github. These keys are setting by an object in var files so I loop like this to generate it:
tasks:
- name: Create ssh key
user:
name: "{{sshConfigFile.user}}"
generate_ssh_key: yes
ssh_key_file: ".ssh/{{item.value.file}}"
state: present
with_dict: "{{sshConfiguration}}"
它工作得很好,但是如何读取这些密钥以通过API将其发送到github?
It works very fine but how read these keys to send it to github via the API ?
推荐答案
EDIT :提出此问题时,可以接受以下解决方案.更高版本的Ansible可能会提供更好的解决方案来解决此问题.因此,如果您不赞成投票,请检查此问题的发布时间.
EDIT: When this question was asked, the following solution was acceptable. Later versions of Ansible may provide a better solution to solve this problem. So if you are downvoting, check when this question was posted.
正如您所说,所有查找都在本地主机上.但是所有这些都可以通过使用 shell
和 register
在远程完成.你能说出你到底想做什么吗?只是一个例子.
As you said, all lookups are on localhost. But all of them can be done on remote by using shell
and register
. Can you tell what exactly you are trying to do? just an example.
- shell: cat "{{remote_file}}"
register: data
- shell: ......
with_xxxx:
这篇关于Ansible:读取远程文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!