main.yml 1.85 KB
Newer Older
1 2 3 4 5 6 7
---

- name: Check if modprobe is available
  stat:
    path: '/sbin/modprobe'
  register: kmod__register_modprobe

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
- name: Install required packages
  package:
    name: '{{ item }}'
    state: 'present'
  with_flattened:
    - '{{ kmod__base_packages }}'
    - '{{ kmod__packages }}'

- name: Make sure that Ansible local facts directory exists
  file:
    path: '/etc/ansible/facts.d'
    state: 'directory'
    owner: 'root'
    group: 'root'
    mode: '0755'

- name: Save kmod local facts
  template:
    src: 'etc/ansible/facts.d/kmod.fact.j2'
    dest: '/etc/ansible/facts.d/kmod.fact'
    owner: 'root'
    group: 'root'
    mode: '0755'
  register: kmod__register_facts

- name: Update Ansible facts if they were modified
  action: setup
  when: kmod__register_facts is changed
36 37 38 39 40

- name: Configure kernel modules
  include_tasks: 'modprobe.yml'
  loop_control:
    loop_var: 'module'
41
  register: kmod__register_modprobe_tasks
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
  with_items: '{{ kmod__combined_modules | parse_kv_items }}'
  when: kmod__enabled|bool

- name: Remove module load configuration
  file:
    dest: '/etc/modules-load.d/{{ item.filename | d(item.name | replace("_","-") + ".conf") }}'
    state: 'absent'
  with_items: '{{ kmod__combined_load | parse_kv_items }}'
  when: kmod__enabled|bool and item.name|d() and item.state|d('present') == 'absent'

- name: Configure module loading at boot
  template:
    src: 'etc/modules-load.d/module.conf.j2'
    dest: '/etc/modules-load.d/{{ item.filename | d(item.name | replace("_","-") + ".conf") }}'
    owner: 'root'
    group: 'root'
    mode: '0644'
  with_items: '{{ kmod__combined_load | parse_kv_items }}'
  when: kmod__enabled|bool and item.name|d() and item.state|d('present') not in [ 'absent', 'ignore' ]

62
- name: Update Ansible facts if the list of load kernel modules might have changed
63
  action: setup
64
  when: kmod__register_modprobe_tasks is changed