In this tutorial, How to use Ansible to read a remote file? Ansible the essential for DevOps Roles.
Ansible read remote file use slurp module
I using slurp module to read a remote file.
- hosts: server1 tasks: - name: slurp file slurp: src: /home/vagrant/devopsroles register: slurp_remote_file - name: Read file debug: msg: "{{ slurp_remote_file['content'] | b64decode }}"
The terminal output as below
Ansible shell module
Using the shell module cat command to read a remote file
- hosts: server1
tasks:
- name: cat file
shell: cat /home/vagrant/devopsroles
register: cat_content_file
- name: echo file
debug:
msg: "{{ cat_content_file.stdout }}"
The terminal output as below
Conclusion
Thought the article, you can use Ansible to read a remote file. I hope will this your helpful. More details refer to Ansible tutorial.