AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Ansible slurp Module: Read File Content from Remote Hosts (ansible.builtin.slurp) — Video Tutorial

Complete guide to ansible.builtin.slurp module. Read and decode file content from remote hosts as base64. Practical examples with register and b64decode.

Watch Video

Watch "Ansible slurp Module: Read File Content from Remote Hosts (ansible.builtin.slurp)" on YouTube

What You'll Learn

Full Tutorial Content

Read a file from remote hosts - Ansible module slurp How to automate the read of `/proc/cpuinfo` file from Linux remote host with Ansible. The file is copied as base 64 encoding and decoded with an Ansible Filter. Ansible Read file from remote hosts - ansible.builtin.slurp - Slurps a file from remote nodes - Fetching a base64-encoded blob of the data in a remote file. Today we're talking about the Ansible module `slurp`. The full name is `ansible.builtin.slurp` which means is part of the collection of modules "builtin" with ansible and shipped with it. This module is pretty stable and out for years and supports Linux and Windows targets. The purpose is to slurp a file from a remote location. Please note that the read operation is going to fetch a base64-encoded blob containing the data in a remote file. Parameters - src string - Remote file path This module has only one parameter "src", which is also mandatory. The parameter "src" specifies the source files in the remote hosts. It must be a file, not a directory. Links - [ansible.builtin.slurp](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/slurp_module.html) ## Playbook Read a file from remote hosts with Ansible Playbook. code ```yaml --- - name: slurp module Playbook hosts: all become: false vars: remotefile: "/proc/cpuinfo" tasks: - name: slurp remote file ansible.builtin.slurp: src: "{{ remotefile }}" register: slurpfile - name: print remote file ansible.builtin.debug: msg: "{{ slurpfile['content'] | b64decode }}" ``` execution ```bash ansible-pilot $ ansible-playbook -i virtualmachines/demo/inventory read\ file\ from\ remote\ hosts/slurp.yml PLAY [slurp module Playbook] ************************************************************************** TASK [Gathering Facts] **************************************************************************** ok: [demo.example.com] TASK [slurp remote file] ************************************************************************** ok: [demo.example.com] TASK [print remote file] ************************************************************************** ok: [demo.example.com] => { "msg": "processor\t: 0\nvendor_id\t: GenuineIntel\ncpu family\t: 6\nmodel\t\t: 158\nmodel name\t: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz\nstepping\t: 10\ncpu MHz\t\t: 2591.998\ncache size\t: 12288 KB\nphysical id\t: 0\nsiblings\t: 1\ncore id\t\t: 0\ncpu cores\t: 1\napicid\t\t: 0\ninitial apicid\t: 0\nfpu\t\t: yes\nfpu_exception\t: yes\ncpuid level\t: 22\nwp\t\t: yes\nflags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq monitor ssse3 cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase avx2 invpcid rdseed clflushopt md_clear flush_l1d\nbugs\t\t: cpu

About This Tutorial

Read the full written article: Ansible slurp Module: Read File Content from Remote Hosts (ansible.builtin.slurp)

Topics Covered

Related Video Tutorials