---
- name: Get CPUs list
  shell: find /sys/devices/system/cpu -type d -name 'cpu[0-9]*'
  register: cpus

- name: Check scaling governor exists for CPUs
  stat:
    path: '{{ item }}/cpufreq/scaling_governor'
  with_items: '{{ cpus.stdout_lines }}'
  register: scaling_governor_stat

- name: Set CPU Scaling Governor
  shell: 'echo {{ value }} > {{ item.item }}/cpufreq/scaling_governor'
  with_items: '{{ scaling_governor_stat.results }}'
  when: item.stat.exists
