---

- name: Install tuned
  yum:
    name: tuned
    state: present

- name: Start tuned and enable at boottime.
  service:
    name: tuned
    state: started
    enabled: true

- name: Enable Tuned profile for low latency
  command: tuned-adm profile virtual-guest

- sysctl:
    name: vm.swappiness
    value: "0"
    state: present
    sysctl_set: yes

---

- name: Install tuned
  yum:
    name: tuned
    state: present

- name: Start tuned and enable at boottime.
  service:
    name: tuned
    state: started
    enabled: true

- name: Get current tuned profile
  command: /usr/sbin/tuned-adm active
  register: tuned_active
  changed_when: false
  ignore_errors: true

- name: Enable Tuned profile for low latency
  command: tuned-adm profile virtual-guest
  when:
    - tuned_active.stdout.find('virtual-guest') == -1

- sysctl:
    name: vm.swappiness
    value: "0"
    state: present
    sysctl_set: yes

Make setting the tuned profile an idempotent operation
Make setting the tuned profile an idempotent operation
