Get memory info using Ansible

Whatever ansible give a memory info in ansible_fact it doesn’t match with memory info
that we get from free -m command. Why this problem happened for that if have any solution plz give me

FWIW. Quoting from 'Performance Data Collection Settings for Runner'
https://ansible-runner.readthedocs.io/en/stable/intro/#performance-data-collection-settings-for-runner

  "Runner is capable of collecting performance data (namely
   cpu usage, memory usage, and pid count) during the execution of a
   playbook run. Resource profiling is made possible by the use of
   control groups ..."

Hi Dip!

Assuming that you are referring to this code, note that that Ansible will run python on the target node - Python the interpreter itself will consume memory. And then if you run the shell module under Ansible, it will spawn a shell which itself will consume memory as well.

  • Rilindo

Hi, All!
My code:

  • name: ===== Блок отримання інформації про виділену RAM ==========================================
    block:
  • name: ===== Вівід інформації про виділену, використану та залишок пам’яті ===================
    ansible.builtin.debug:
    msg: “Виділена пам’ять: {{ ansible_memory_mb.real.total }} | Використана: {{ ansible_memory_mb.real.used }} | Залишилось: {{ ansible_memory_mb.real.total - ansible_memory_mb.real.used }} ({{ ((1-ansible_memory_mb.real.used/ansible_memory_mb.real.total)*100)|int }}%)”

stdout:
ok: [vl-nr-app1] => {
“msg”: “Виділена пам’ять: 2619 | Використана: 2004 | Залишилось: 615 (23%)”
}
ok: [vl-nr-app2] => {
“msg”: “Виділена пам’ять: 2619 | Використана: 1983 | Залишилось: 636 (24%)”
}
ok: [al-nr-app1] => {
“msg”: “Виділена пам’ять: 2619 | Використана: 2073 | Залишилось: 546 (20%)
}

вторник, 8 февраля 2022 г. в 19:16:40 UTC+2, Rilindo Foster: