AnsiblePilot — Ansible Automation Platform and Enterprise Ansible

AnsiblePilot covers Red Hat Ansible Automation Platform (AAP) and enterprise Ansible: install and upgrade paths, Event-Driven Ansible, security and day-2 operations, plus Luca Berton's books, videos and training.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 9 technical books published by Apress and Leanpub, 4 of them on Ansible, 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

Ansible slurp module guide: read file content from remote hosts as base64. Learn b64decode, parse JSON, and compare configurations.

Watch on YouTube · Read the written article

Tutorial summary

What you'll learn

  • Ansible slurp: Read Files from Remote Hosts
  • Ansible Read file from remote hosts
  • Parameters
  • Links
  • code
  • execution
  • idempotency
  • verification
  • Conclusion
  • Basic slurp
Ansible slurp: Read Files from Remote Hosts Ansible slurp is a module that reads files from remote hosts and returns their content as base64-encoded data. This guide shows you how to use slurp to read and decode remote files like `/proc/cpuinfo`, configuration files, and more. 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

About this tutorial

  • Author: Luca Berton
  • Difficulty: Beginner
  • Read time: 7 min
  • Category: troubleshooting

Topics covered

Related video tutorials