linux - How can an operator funtion in ansible with "set_fact" and "when" -


how can use set_fact module "when" use below conditions? need "shmall" value set depending upon total memory in rhel server. need know how operators work in ansible.

- name: total available memory shell: cat /proc/meminfo | grep memtotal | awk '{print $2}' register: memtotal      # rhel7,shmall setting should (physical memory – memory system) / page size 4096 pagesize. - name: shmall value set memory size less 16g set_fact:     shmall: 3670016     when: (memtotal le "16777216") | int - name: shmall value set memory size between 16g , 32g set_fact:     shmall: 7340032     when: (memtotal gt "16777216" ,  memtotal le "33554432") | int - name: shmall value set memory size between 32g , 64g set_fact:     shmall: 14680064     when: (memtotal gt "33554432" ,  memtotal  le "6710886") | int - name: shmall value set memory size between 64g , 256g set_fact:     shmall: 57671680     when: (memtotal  gt "67108864" ,  memtotal  le "268435456") | int 

you can calculate small value:

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

Comments