Question:
I generate files with ansible on remote host and after this generation, I would like to read theses files in another task.
I don’t find any module to read remote file with ansible (lookup seems only on local host).
Do you know a module like this ?
Here is my use case:
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:
1 2 3 4 5 6 7 8 9 |
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}}" |
It works very fine but how read these keys to send it to github via the API ?
Answer:
Note that when this question was asked, the following solution was acceptable. Later versions of Ansible may provide a better solution to solve this problem.
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.
1 2 3 4 5 6 |
- shell: cat "{{remote_file}}" register: data - shell: ...... with_xxxx: |