Skip to content

Instantly share code, notes, and snippets.

Forked from keithchambers/gist:80b60559ad83cebf1672
Last active March 10, 2020 21:15
What would you like to do?
Ansible role to set 'noop' i/o scheduler (CentOS 7)


  • make the IO scheduler configurable
  • register grub_test to match the actual variable usage
  • changed stdout to stdout_lines
  • make block_devs work.
    • it looks gross, but previously interpreted block_devs.stdout_lines as a literal string

Ansible version: 2.7

- name: test if grub configured for {{ io_scheduler }} i/o scheduler
command: egrep -q 'elevator={{ io_scheduler }}' /boot/grub2/grub.cfg
register: grub_test
changed_when: no
failed_when: grub_test.rc == 2
- name: configure grub for {{ io_scheduler }} i/o scheduler
sudo: yes
command: grubby --update-kernel=ALL --args=elevator={{ io_scheduler }}
when: grub_test.rc == 1
- name: get list of block devices to test
shell: ls /sys/block/ | egrep '^([shv]|xv])d[a-z]$'
register: block_devs
changed_when: no
- name: test if block device using {{ io_scheduler }} i/o scheduler
shell: cat /sys/block/{{ item }}/queue/scheduler | egrep -q '\[{{ io_scheduler }}\]'
with_items: "{{ block_devs.stdout_lines }}"
register: sched_test
changed_when: sched_test.rc == 1
failed_when: sched_test.rc == 2
- name: set block device to use {{ io_scheduler }} i/o scheduler
sudo: yes
shell: echo '{{ io_scheduler }}' > /sys/block/{{ item }}/queue/scheduler
with_items: "{{ block_devs.stdout_lines }}"
when: sched_test.changed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment