Get memory info using Ansible

1,189 views
Skip to first unread message

Dip Giri

unread,
Feb 8, 2022, 9:46:58 AM2/8/22
to Ansible Project
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 

---
- name: Setup server
hosts: localhost
tasks:

- name: test
shell: free -m
register: xyz

- name: Print service status
debug:
msg: "{{ansible_memory_mb.real}}"

- name: Print service status
debug:
msg: "{{xyz.stdout.split('\n')}}"

Vladimir Botka

unread,
Feb 8, 2022, 11:12:11 AM2/8/22
to Dip Giri, ansible...@googlegroups.com
On Tue, 8 Feb 2022 06:46:58 -0800 (PST)
Dip Giri <dipakgir...@gmail.com> wrote:

> Whatever ansible give a memory info in ansible_fact it doesn't match with
> memory info that we get from *free -m *command.

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 ..."

--
Vladimir Botka

Rilindo Foster

unread,
Feb 8, 2022, 12:16:40 PM2/8/22
to ansible...@googlegroups.com
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

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/74109954-cb3c-4b72-a5b0-34f9e425f16fn%40googlegroups.com.

Message has been deleted

Петрук Ігор Степанович

unread,
Sep 21, 2023, 6:38:59 AM9/21/23
to Ansible Project
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:
Reply all
Reply to author
Forward
0 new messages