Odd results from query of /proc/meminfo?

23 views
Skip to first unread message

Jibun no Kage .

unread,
Jan 14, 2022, 12:31:29 PM1/14/22
to ansible...@googlegroups.com
Odd results from query of /proc/meminfo?

When I do the following from shell...
# cat /proc/meminfo | grep MemTotal
MemTotal:        8087276 kB

But when I do the same via Ansible...
ok: [192.168.1.212] => {
    "msg": "Pi Memory Total: MemTotal:         957160 kB"
}

Ansible Source...
    - name: Memory Total
      #shell: "cat /proc/meminfo | grep MemTotal | cut -d ':' -f2 | cut
-d 'k' -f1 | tr -d ' '"
      shell: "cat /proc/meminfo | grep MemTotal"
      register: m
      changed_when: False

    - name: Memory Total
      debug:
        msg: "Memory Total: {{ m.stdout }}"

Returned value is greater than physical memory size!

Stefan Hornburg (Racke)

unread,
Jan 14, 2022, 2:22:41 PM1/14/22
to ansible...@googlegroups.com
On 14/01/2022 18:23, Jibun no Kage . wrote:
> Odd results from query of /proc/meminfo?
>
> When I do the following from shell...
> # cat /proc/meminfo | grep MemTotal
> MemTotal:        8087276 kB
>
> But when I do the same via Ansible...
> ok: [192.168.1.212] => {
>     "msg": "Pi Memory Total: MemTotal:         957160 kB"
> }
>

Why messing with the shell when the information is already present in the facts?

- name: Show memory
debug:
msg: "{{ ansible_memory_mb }}"

TASK [Show memory] *************************************************************
ok: [bullseye-test-box] =>
msg:
nocache:
free: 828
used: 1154
real:
free: 82
total: 1982
used: 1900
swap:
cached: 0
free: 0
total: 0
used: 0

Regards
Racke

> Ansible Source...
>     - name: Memory Total
>       #shell: "cat /proc/meminfo | grep MemTotal | cut -d ':' -f2 | cut -d 'k' -f1 | tr -d ' '"
>       shell: "cat /proc/meminfo | grep MemTotal"
>       register: m
>       changed_when: False
>
>     - name: Memory Total
>       debug:
>         msg: "Memory Total: {{ m.stdout }}"
>
> Returned value is greater than physical memory size!
>


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration.

OpenPGP_signature
Reply all
Reply to author
Forward
0 new messages