Ansible: read remote file
You can try the 'fetch' module, which will retrieve the key file to a destination path on localhost
:
fetch:
src: ".ssh/{{item.value.file}}"
dest:"/tmp/ssh_keys/{{item.value.file}}"
flat: yes
with_dict: "{{sshConfiguration}}"
Either run with the --diff flag (outputs a diff when the destination file changes) ..
ansible-playbook --diff server.yaml
or slurp it up ..
- name: Slurp hosts file
slurp:
src: /etc/hosts
register: slurpfile
- debug: msg="{{ slurpfile['content'] | b64decode }}"
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.
- shell: cat "{{remote_file}}"
register: data
- shell: ......
with_xxxx: