Using a Jinja template
- Identify the name of the variable on the remote host that you want to use
ansible zubi -m setup | grep mounts
"ansible_mounts": [
- Create the Jinja template and give it some format
cat /etc/ansible/templates/df.jinja2
{{ ansible_mounts | json_query('[].mount') | to_nice_yaml }}
- Create the playbook that will populate the file. Using the template module
---
- hosts: zubi
become: yes
become_user: root
become_method: sudo
tasks:
- name: build filesystem list
template:
src: /etc/ansible/templates/df.jinja2
dest: /var/lsoffs
Result:
[ec2-user@zubi ~]$ cat /var/lsoffs
- /
- /var
- /opt
- /tmp
No comments:
Post a Comment