Solution: Reading a File with Ansible
Look at the solution to the previous exercise.
We'll cover the following...
---
- name: Exercise
hosts: all
vars:
myfile: "/proc/cpuinfo"
tasks:
- name: Get the content of the cpuinfo
ansible.builtin.slurp:
src: "{{ myfile }}"
register: file_details
- name: Display cpuinfo
ansible.builtin.debug:
msg: "{{ file_details.content | b64decode }}"Code to read the cpuinfo file
Explanation
For the
read_file.ymlfile:Line 2: We write the play named
Exercise.Line 3: We specify the host
allfor the target hosts of execution.Lines 4-5: We create a variable named
myfilewith the ...
Ask