Refactor host specific kernel module tasks

Update the 'openstack_host_specific_kernel_modules' tasks so that they
no longer need to skip ansible lint checking. The kernel configuration
file is now slurped and searched through to find out if the provided
list of modules are valid and loadable.

For testing, a 'openstack_host_specific_kernel_modules' test var and
assertion has been added.

Change-Id: I5d26b055fe8582b29ff40e0daa896bf1b7207161
This commit is contained in:
Jimmy McCrory 2017-04-11 15:36:50 -07:00
parent 4da878d8bd
commit a91449ff59
3 changed files with 28 additions and 43 deletions

View File

@ -31,65 +31,46 @@
- openstack_host_kernel_modules | length > 0
- item != ''
- name: get kernel release
command: "uname -r"
register: uname
changed_when: false
- name: check how kernel modules are implemented (statically builtin, dynamic, not set)
command: grep {{ item.pattern }} /boot/config-{{ uname.stdout}}
slurp:
src: "/boot/config-{{ ansible_kernel }}"
register: modules
with_items: "{{ openstack_host_specific_kernel_modules }}"
when:
- openstack_host_specific_kernel_modules | length > 0
- groups["{{ item.group }}"] is defined
- inventory_hostname in groups["{{ item.group }}"]
failed_when: false
when: openstack_host_specific_kernel_modules | length > 0
- name: fail if a specific kernel module is not set
fail:
msg: "{{ item['stdout'] }}"
with_items: "{{ modules['results'] | default([]) }}"
msg: "{{ item.pattern }} is not set"
with_items: "{{ openstack_host_specific_kernel_modules }}"
when:
- modules['changed'] | bool
- "'is not set' in item['stdout']"
tags:
# Do not hit ANSIBLE0016
- skip_ansible_lint
- groups[item.group] is defined
- inventory_hostname in groups[item.group]
- (modules.content | b64decode).find(item.pattern + ' is not set') != -1
- name: fail if a specific pattern is not valid
fail:
msg: "'pattern:' {{ item['item']['pattern'] }} 'is not valid. Search results for pattern lead to:' {{ item['stdout'] }}"
with_items: "{{ modules['results'] | default([]) }}"
msg: "{{ item.pattern }} is not a valid pattern"
with_items: "{{ openstack_host_specific_kernel_modules }}"
when:
- modules['changed'] | bool
- "'=y' not in item['stdout']"
- "'=m' not in item['stdout']"
tags:
# Do not hit ANSIBLE0016
- skip_ansible_lint
- groups[item.group] is defined
- inventory_hostname in groups[item.group]
- (modules.content | b64decode).find(item.pattern + '=y') == -1
- (modules.content | b64decode).find(item.pattern + '=m') == -1
- name: "Ensure dynamic specific kernel module(s) are loaded"
modprobe:
name: "{{ item['item']['name'] }}"
with_items: "{{ modules['results'] | default([]) }}"
name: "{{ item.name }}"
with_items: "{{ openstack_host_specific_kernel_modules }}"
when:
- modules['changed'] | bool
- inventory_hostname in groups[item["item"]["group"]]
- "'=m' in item['stdout']"
tags:
# Do not hit ANSIBLE0016
- skip_ansible_lint
- groups[item.group] is defined
- inventory_hostname in groups[item.group]
- (modules.content | b64decode).find(item.pattern + '=m') != -1
- name: "Ensure dynamic specific kernel module(s) loaded at boot"
lineinfile:
dest: "{{ openstask_host_module_file }}"
line: "{{ item['item']['name'] }}"
with_items: "{{ modules['results'] | default([]) }}"
line: "{{ item.name }}"
with_items: "{{ openstack_host_specific_kernel_modules }}"
when:
- modules['changed'] | bool
- inventory_hostname in groups[item["item"]["group"]]
- "'=m' in item['stdout']"
tags:
# Do not hit ANSIBLE0016
- skip_ansible_lint
- groups[item.group] is defined
- inventory_hostname in groups[item.group]
- (modules.content | b64decode).find(item.pattern + '=m') != -1

View File

@ -0,0 +1,3 @@
---
openstack_host_specific_kernel_modules:
- { name: "ebtables", pattern: "CONFIG_BRIDGE_NF_EBTABLES", group: "hosts" }

View File

@ -72,6 +72,7 @@
assert:
that:
- "'dm_multipath' in modules_content"
- "'ebtables' in modules_content"
- "'vm.swappiness' in sysctl_content"
- "'127.111.111.101 test1.openstack.local test1' in hosts_content"
- "'127.111.111.102 test2.openstack.local test2' in hosts_content"