Ansible:读取远程文件 [英] Ansible: read remote file

查看:35
本文介绍了Ansible:读取远程文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在远程主机上用 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 ?

推荐答案

请注意,在提出此问题时,以下解决方案是可以接受的.更高版本的 Ansible 可能会提供更好的解决方案来解决这个问题.

正如您所说,所有查找都在本地主机上.但是所有这些都可以通过使用 shellregister 在远程完成.你能说出你到底想做什么吗?只是一个例子.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆