Member-only story
Read a file into a variable on host — Ansible lookup plugin file
How to automate the reading of example.txt file on Ansible host, assign to a variable and use in your Ansible Playbook code.
How to read a file into a variable on the host with Ansible?
I’m going to show you a live demo with some simple Ansible code.
I’m Luca Berton and welcome to today’s episode of Ansible Pilot.
Ansible read a file into a variable
- `
ansible.builtin.file
` - read file contents
Let’s deep dive into the Ansible lookup plugin file.
Plugins are a way to expand the Ansible functionality. With lookup plugins specifically, you can load variables or templates with information from external sources.
The full name is `ansible.builtin.file
`, it’s part of `ansible-core
` and is included in all Ansible installations.
The purpose of the `file
` lookup plugin is to read file contents.