Ansible 使用jinja2模板 统计资源使用情况
template.j2 模板
----------------------------------------------------------------------------- {{ansible_facts.hostname}}:{{ansible_default_ipv4.address}} This system's total memory is: {{ ansible_memtotal_mb }}MBs. The current free memory is: {{ ansible_memory_mb.nocache.free }} MBs. {% for i in ansible_mounts if i.block_used/i.block_total>0.8 %} The mount disk more 80%:{{i.mount}}use percentage :{{i.block_used/i.block_total}} {% endfor%}
Playbook
--- - name: test temaplte hosts: localhost tasks: - name: test template template: src: template.j2 dest: /home/operater-hryt/myansible/result.j2
输出样式