chris-short / rak8s

Stand up a Raspberry Pi based Kubernetes cluster with Ansible
MIT License
365 stars 112 forks source link

reduce gpu memory #48

Closed StoicPerlman closed 5 years ago

StoicPerlman commented 5 years ago

Reduce gpu memory

Description

Set gpu memory to minimum value as described in readme

Testing

Tested on 4 node rpi 3b+ cluster

Issues

At least part of issue https://github.com/rak8s/rak8s/issues/9

StoicPerlman commented 5 years ago

The lineinfile would probably be sufficient, but I wanted to make sure this did not override a custom change by the user so I added the grep.

solvaholic commented 5 years ago

Thank you for this @StoicPerlman!

I'm learning to use Ansible for things and your example helped me see how to automate some Raspbian configs. Setting a couple notes here in case they'll help someone else along...

If you want to override other custom gpu_mem settings when you set up a rak8s cluster you could use the replace module to comment out any gpu_mem= that aren't 16:

ansible prod -m replace -a 'path="/boot/config.txt" regexp="^gpu_mem=(?!16$)([0-9]+)" replace="#gpu_mem=\1"'

When I added that to the roles/common tasks like this it worked OK:

- name: comment out gpu memory settings
  replace:
    path: /boot/config.txt
    regexp: '^gpu_mem=(?!16$)([0-9]+)'
    replace: '#gpu_mem=\1'
  register: commented_gpu_mem

If you want to comment your custom gpu_mem setting you could use blockinfile like so:

ansible prod -m blockinfile -a "path='/boot/config.txt' state='present' marker='# {mark} Set gpu_mem to 16MB for rak8s' block='gpu_mem=16' create='yes' owner='root' group='root' mode=755"

When I added that to the roles/common tasks like this, though, running it returned an error about operation not permitted:

- name: set gpu memory to 16MB
  blockinfile:
    path: /boot/config.txt
    state: present
    marker: '# {mark} Set gpu_mem to 16MB for rak8s'
    block: 'gpu_mem=16'
    insertafter: EOF
    create: yes
    owner: root
    group: root
    mode: 755
  register: set_gpu_mem
chris-short commented 5 years ago

Thank you!