Ansible read remote file

In this tutorial, How to use Ansible to read a remote file? Ansible the essential for DevOps Roles.

Ansible 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 belowAnsible read remote file

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

Ansible read remote file shell module

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.

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment moderation is enabled. Your comment may take some time to appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.