Ansible read remote file

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
  - name: slurp file
     src: /home/vagrant/devopsroles
    register: slurp_remote_file

  - name: Read file
     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
    - name: cat file
      shell: cat /home/vagrant/devopsroles
      register: cat_content_file

    - name: echo file
        msg: "{{ cat_content_file.stdout }}"

The terminal output as below

Ansible read remote file shell module


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 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 *

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