在以下条件下,如何使用带有“何时”的“设置事实”模块?我需要根据RHEL服务器中的总内存设置“shmall”值。
我需要知道接线员是怎么工作的。
- name: Total Available Memory
shell: cat /proc/meminfo | grep MemTotal | awk '{print $2}'
register: MemTotal
# for RHEL7,SHMALL Setting should be (PHYSICAL MEMORY – MEMORY FOR SYSTEM) / PAGE SIZE with 4096 pagesize.
- name: SHMALL value to set for memory size less than 16G
set_fact:
shmall: 3670016
when: (MemTotal le "16777216") | int
- name: SHMALL value to set for memory size between 16G and 32G
set_fact:
shmall: 7340032
when: (MemTotal gt "16777216" and MemTotal le "33554432") | int
- name: SHMALL value to set for memory size between 32G and 64G
set_fact:
shmall: 14680064
when: (MemTotal gt "33554432" and MemTotal le "6710886") | int
- name: SHMALL value to set for memory size between 64G and 256G
set_fact:
shmall: 57671680
when: (MemTotal gt "67108864" and MemTotal le "268435456") | int
最佳答案
你可以计算你的小价值:
---
- hosts: localhost
vars:
mem_gb: "{{ ansible_memtotal_mb/1024 }}"
mem_pow2: "{{ 2 | pow(((mem_gb|int|log)/(2|log)) | round(0,'ceil')) }}"
shmall_calculated: "{{ ((mem_pow2|int)*0.875*1024*1024*1024/4096) | int }}"
tasks:
- debug:
msg: "{{ shmall_calculated }}"