If only I could make my playbook assign half the server’s RAM…

You can! Use the server’s facts.

Example using ansible_memory_mb.real.total :

- hosts: pentaho
  gather_facts: yes
  tasks:
  - name: Adjust JAVAMAXMEM in kitchen.sh to half the total RAM
    replace:
      path: /opt/pentaho/pdi/kitchen.sh
      regexp: '(\s+)JAVAMAXMEM=\"512\"$'
      replace: '\1JAVAMAXMEM="{{ ansible_memory_mb.real.total//2 }}"'
      backup: yes

Extra tip

  • Get filtered facts
$ ansible example -m setup -a 'filter=*mem*'
example.supermasita.com | SUCCESS => {
    "ansible_facts": {
        "ansible_memfree_mb": 107, 
        "ansible_memory_mb": {
            "nocache": {
                "free": 1647, 
                "used": 353
            }, 
            "real": {
                "free": 107, 
                "total": 2000, 
                "used": 1893
            }, 
            "swap": {
                "cached": 0, 
                "free": 0, 
                "total": 0, 
                "used": 0
            }
        }, 
        "ansible_memtotal_mb": 2000
    }, 
    "changed": false
}