From a50385720909582bb7aeff9cfb0a4165e452c12c Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Wed, 19 Jun 2019 19:55:43 -0500 Subject: [PATCH] Import tripleo-module-load role The tripleo module-load-role from tripleo-common has been imported into tripleo-ansible. Role tests have been added using molecule testing the loading and unloading capbailities of this role. Documentation hooks have been created showing how the role can be used. Change-Id: Icd788f12e78b0c7cf2545b133df1d0a4b8f80018 Signed-off-by: Kevin Carter --- doc/source/roles/role-tripleo-module-load.rst | 31 ++++++++ role-addition.yml | 2 +- tox.ini | 18 +++++ .../tripleo-module-load/defaults/main.yml | 38 ++++++++++ .../roles/tripleo-module-load/meta/main.yml | 44 +++++++++++ .../molecule/default/Dockerfile | 37 +++++++++ .../molecule/default/molecule.yml | 68 +++++++++++++++++ .../molecule/default/playbook.yml | 23 ++++++ .../molecule/default/prepare.yml | 26 +++++++ .../molecule/default/verify.yml | 15 ++++ .../molecule/remove_module/Dockerfile | 37 +++++++++ .../molecule/remove_module/molecule.yml | 68 +++++++++++++++++ .../molecule/remove_module/playbook.yml | 27 +++++++ .../molecule/remove_module/prepare.yml | 26 +++++++ .../molecule/remove_module/verify.yml | 15 ++++ .../roles/tripleo-module-load/tasks/main.yml | 76 +++++++++++++++++++ .../templates/module-load.conf.j2 | 2 + zuul.d/molecule.yaml | 11 ++- 18 files changed, 562 insertions(+), 2 deletions(-) create mode 100644 doc/source/roles/role-tripleo-module-load.rst create mode 100644 tripleo_ansible/roles/tripleo-module-load/defaults/main.yml create mode 100644 tripleo_ansible/roles/tripleo-module-load/meta/main.yml create mode 100644 tripleo_ansible/roles/tripleo-module-load/molecule/default/Dockerfile create mode 100644 tripleo_ansible/roles/tripleo-module-load/molecule/default/molecule.yml create mode 100644 tripleo_ansible/roles/tripleo-module-load/molecule/default/playbook.yml create mode 100644 tripleo_ansible/roles/tripleo-module-load/molecule/default/prepare.yml create mode 100644 tripleo_ansible/roles/tripleo-module-load/molecule/default/verify.yml create mode 100644 tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/Dockerfile create mode 100644 tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/molecule.yml create mode 100644 tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/playbook.yml create mode 100644 tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/prepare.yml create mode 100644 tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/verify.yml create mode 100644 tripleo_ansible/roles/tripleo-module-load/tasks/main.yml create mode 100644 tripleo_ansible/roles/tripleo-module-load/templates/module-load.conf.j2 diff --git a/doc/source/roles/role-tripleo-module-load.rst b/doc/source/roles/role-tripleo-module-load.rst new file mode 100644 index 000000000..6f4f0ad54 --- /dev/null +++ b/doc/source/roles/role-tripleo-module-load.rst @@ -0,0 +1,31 @@ +========================================== +TripleO-Ansible Role - tripleo-module-load +========================================== + +This role provides for the following services: + + * tripleo-module-load + + +Default variables +~~~~~~~~~~~~~~~~~ + +.. literalinclude:: ../../../tripleo_ansible/roles/tripleo-module-load/defaults/main.yml + :language: yaml + :start-after: under the License. + + +Example default playbook +~~~~~~~~~~~~~~~~~~~~~~~~ + +.. literalinclude:: ../../../tripleo_ansible/roles/tripleo-module-load/molecule/default/playbook.yml + :language: yaml + :start-after: under the License. + + +Example module remove playbook +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. literalinclude:: ../../../tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/playbook.yml + :language: yaml + :start-after: under the License. diff --git a/role-addition.yml b/role-addition.yml index fe6c9f67e..ceb362e48 100644 --- a/role-addition.yml +++ b/role-addition.yml @@ -83,7 +83,7 @@ "name": new_job_name, "parent": "tripleo-ansible-centos", "files": [ - "^roles/" ~ role_name ~ "/.*" + "^tripleo_ansible/roles/" ~ role_name ~ "/.*" ], "vars": { "tox_envlist": "mol-" ~ role_name diff --git a/tox.ini b/tox.ini index 5f1363a87..91296c213 100644 --- a/tox.ini +++ b/tox.ini @@ -213,3 +213,21 @@ basepython = {[testenv:mol]basepython} deps = {[testenv:mol]deps} changedir = {toxinidir}/tripleo_ansible/roles/tripleo-create-admin commands = python -m pytest --color=yes --html={envlogdir}/reports.html --self-contained-html {tty:-s} {toxinidir}/tests/test_molecule.py --scenario=keygen + +[testenv:mol-tripleo-module-load] +basepython = {[testenv:mol]basepython} +deps = {[testenv:mol]deps} +changedir = {toxinidir}/tripleo_ansible/roles/tripleo-module-load +commands = python -m pytest --color=yes --html={envlogdir}/reports.html --self-contained-html {tty:-s} {toxinidir}/tests/test_molecule.py + +[testenv:mol-tripleo-module-load-default] +basepython = {[testenv:mol]basepython} +deps = {[testenv:mol]deps} +changedir = {toxinidir}/tripleo_ansible/roles/tripleo-module-load +commands = python -m pytest --color=yes --html={envlogdir}/reports.html --self-contained-html {tty:-s} {toxinidir}/tests/test_molecule.py --scenario=default + +[testenv:mol-tripleo-module-load-remove_module] +basepython = {[testenv:mol]basepython} +deps = {[testenv:mol]deps} +changedir = {toxinidir}/tripleo_ansible/roles/tripleo-module-load +commands = python -m pytest --color=yes --html={envlogdir}/reports.html --self-contained-html {tty:-s} {toxinidir}/tests/test_molecule.py --scenario=remove_module diff --git a/tripleo_ansible/roles/tripleo-module-load/defaults/main.yml b/tripleo_ansible/roles/tripleo-module-load/defaults/main.yml new file mode 100644 index 000000000..cce67bda2 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-module-load/defaults/main.yml @@ -0,0 +1,38 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +# All variables intended for modification should place placed in this file. + +# Load specific kernel modules using a list of hashes. This variable also +# takes the keyword "params" and "state". Params is assumed to be `null` and +# state is assumed to be "present"; tate can be either "present" or "absent". +# +# modules: +# - name: foo +# params: 'bar baz' +# - name: starwars +# - name: starwars +# state: absent +# +# NOTE(cloudnull): This role used to use a non-namespaced option, which has a high +# probability of creating conflicts with other roles in the greater +# ansible ecosystem. To ensure that we're able to retain existing +# variable functionality the "modules" option will supersede +# "tripleo_modules" if defined. This default should be removed +# just as soon as we're validate that the non-namespaced option +# is no longer in use. +tripleo_modules: "{{ modules | default([]) }}" diff --git a/tripleo_ansible/roles/tripleo-module-load/meta/main.yml b/tripleo_ansible/roles/tripleo-module-load/meta/main.yml new file mode 100644 index 000000000..e65e965c9 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-module-load/meta/main.yml @@ -0,0 +1,44 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +galaxy_info: + author: OpenStack + description: TripleO OpenStack Role -- tripleo-module-load + company: Red Hat + license: Apache-2.0 + min_ansible_version: 2.7 + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + platforms: + - name: Fedora + versions: + - 28 + - name: CentOS + versions: + - 7 + + galaxy_tags: + - tripleo + + +# List your role dependencies here, one per line. Be sure to remove the '[]' above, +# if you add dependencies to this list. +dependencies: [] diff --git a/tripleo_ansible/roles/tripleo-module-load/molecule/default/Dockerfile b/tripleo_ansible/roles/tripleo-module-load/molecule/default/Dockerfile new file mode 100644 index 000000000..1b91a0e0b --- /dev/null +++ b/tripleo_ansible/roles/tripleo-module-load/molecule/default/Dockerfile @@ -0,0 +1,37 @@ +# Molecule managed +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash {{ item.pkg_extras | default('') }} && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl python-setuptools bash {{ item.pkg_extras | default('') }} && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml {{ item.pkg_extras | default('') }} && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates {{ item.pkg_extras | default('') }}; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates {{ item.pkg_extras | default('') }} && xbps-remove -O; fi + +{% for pkg in item.easy_install | default([]) %} +# install pip for centos where there is no python-pip rpm in default repos +RUN easy_install {{ pkg }} +{% endfor %} + + +CMD ["sh", "-c", "while true; do sleep 10000; done"] diff --git a/tripleo_ansible/roles/tripleo-module-load/molecule/default/molecule.yml b/tripleo_ansible/roles/tripleo-module-load/molecule/default/molecule.yml new file mode 100644 index 000000000..4e21e8195 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-module-load/molecule/default/molecule.yml @@ -0,0 +1,68 @@ +--- +driver: + name: docker + +log: true + +platforms: + - name: centos7 + hostname: centos7 + image: centos:7 + dockerfile: Dockerfile + pkg_extras: python-setuptools + easy_install: + - pip + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + command: /sbin/init + tmpfs: + - /run + - /tmp + capabilities: + - ALL + volumes: + - /dev:/dev + - /lib/modules:/lib/modules + + - name: fedora28 + hostname: fedora28 + image: fedora:28 + dockerfile: Dockerfile + pkg_extras: python*-setuptools + environment: + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + command: /sbin/init + privileged: true + tmpfs: + - /run + - /tmp + capabilities: + - ALL + volumes: + - /dev:/dev + - /lib/modules:/lib/modules + +provisioner: + name: ansible + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + +scenario: + test_sequence: + - destroy + - create + - prepare + - converge + - verify + - destroy + +lint: + enabled: false + +verifier: + name: testinfra + lint: + name: flake8 diff --git a/tripleo_ansible/roles/tripleo-module-load/molecule/default/playbook.yml b/tripleo_ansible/roles/tripleo-module-load/molecule/default/playbook.yml new file mode 100644 index 000000000..9babd1b68 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-module-load/molecule/default/playbook.yml @@ -0,0 +1,23 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +- name: Converge + hosts: all + roles: + - role: "tripleo-module-load" + tripleo_modules: + - name: dummy diff --git a/tripleo_ansible/roles/tripleo-module-load/molecule/default/prepare.yml b/tripleo_ansible/roles/tripleo-module-load/molecule/default/prepare.yml new file mode 100644 index 000000000..eaca6e17c --- /dev/null +++ b/tripleo_ansible/roles/tripleo-module-load/molecule/default/prepare.yml @@ -0,0 +1,26 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +- name: Prepare + hosts: all + roles: + - role: test_deps + post_tasks: + - name: Install additional dependencies + package: + name: kmod + state: present diff --git a/tripleo_ansible/roles/tripleo-module-load/molecule/default/verify.yml b/tripleo_ansible/roles/tripleo-module-load/molecule/default/verify.yml new file mode 100644 index 000000000..dfd4c7352 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-module-load/molecule/default/verify.yml @@ -0,0 +1,15 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. diff --git a/tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/Dockerfile b/tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/Dockerfile new file mode 100644 index 000000000..1b91a0e0b --- /dev/null +++ b/tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/Dockerfile @@ -0,0 +1,37 @@ +# Molecule managed +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash {{ item.pkg_extras | default('') }} && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl python-setuptools bash {{ item.pkg_extras | default('') }} && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml {{ item.pkg_extras | default('') }} && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates {{ item.pkg_extras | default('') }}; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates {{ item.pkg_extras | default('') }} && xbps-remove -O; fi + +{% for pkg in item.easy_install | default([]) %} +# install pip for centos where there is no python-pip rpm in default repos +RUN easy_install {{ pkg }} +{% endfor %} + + +CMD ["sh", "-c", "while true; do sleep 10000; done"] diff --git a/tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/molecule.yml b/tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/molecule.yml new file mode 100644 index 000000000..4e21e8195 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/molecule.yml @@ -0,0 +1,68 @@ +--- +driver: + name: docker + +log: true + +platforms: + - name: centos7 + hostname: centos7 + image: centos:7 + dockerfile: Dockerfile + pkg_extras: python-setuptools + easy_install: + - pip + environment: &env + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + command: /sbin/init + tmpfs: + - /run + - /tmp + capabilities: + - ALL + volumes: + - /dev:/dev + - /lib/modules:/lib/modules + + - name: fedora28 + hostname: fedora28 + image: fedora:28 + dockerfile: Dockerfile + pkg_extras: python*-setuptools + environment: + http_proxy: "{{ lookup('env', 'http_proxy') }}" + https_proxy: "{{ lookup('env', 'https_proxy') }}" + command: /sbin/init + privileged: true + tmpfs: + - /run + - /tmp + capabilities: + - ALL + volumes: + - /dev:/dev + - /lib/modules:/lib/modules + +provisioner: + name: ansible + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + +scenario: + test_sequence: + - destroy + - create + - prepare + - converge + - verify + - destroy + +lint: + enabled: false + +verifier: + name: testinfra + lint: + name: flake8 diff --git a/tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/playbook.yml b/tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/playbook.yml new file mode 100644 index 000000000..5d0087d10 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/playbook.yml @@ -0,0 +1,27 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +- name: Converge + hosts: all + roles: + - role: "tripleo-module-load" + tripleo_modules: + - name: dummy + - role: "tripleo-module-load" + tripleo_modules: + - name: dummy + state: absent diff --git a/tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/prepare.yml b/tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/prepare.yml new file mode 100644 index 000000000..eaca6e17c --- /dev/null +++ b/tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/prepare.yml @@ -0,0 +1,26 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +- name: Prepare + hosts: all + roles: + - role: test_deps + post_tasks: + - name: Install additional dependencies + package: + name: kmod + state: present diff --git a/tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/verify.yml b/tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/verify.yml new file mode 100644 index 000000000..dfd4c7352 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/verify.yml @@ -0,0 +1,15 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. diff --git a/tripleo_ansible/roles/tripleo-module-load/tasks/main.yml b/tripleo_ansible/roles/tripleo-module-load/tasks/main.yml new file mode 100644 index 000000000..30b995615 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-module-load/tasks/main.yml @@ -0,0 +1,76 @@ +--- +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +# "tripleo-module-load" will search for and load any operating system variable file + +- name: Check whether /etc/modules-load.d exists + stat: + path: /etc/modules-load.d + register: modules_load_stat + +- name: Check whether /etc/modules-load.d exists + stat: + path: /etc/modules + register: modules_file + +- name: "Load modules" + become: true + modprobe: + name: "{{ item.name }}" + params: "{{ item.params | default(omit) }}" + state: "{{ item.state | default('present') }}" + loop: "{{ tripleo_modules }}" + loop_control: + label: "{{ item.name }}" + +- name: "Persist modules via modules-load.d" + become: true + template: + dest: "/etc/modules-load.d/{{ item.name }}.conf" + src: module-load.conf.j2 + loop: "{{ tripleo_modules }}" + loop_control: + label: "{{ item.name }}" + when: + - modules_load_stat.stat.exists | bool + - (item.state | default('present')) == 'present' + +- name: "Drop module persistence" + become: true + file: + path: "/etc/modules-load.d/{{ item.name }}.conf" + state: absent + loop: "{{ tripleo_modules }}" + loop_control: + label: "{{ item.name }}" + when: + - modules_load_stat.stat.exists | bool + - (item.state | default('present')) == 'absent' + +- name: "Set modules persistence via /etc/modules" + become: true + lineinfile: + dest: /etc/modules + line: "{{ item.name }} {{ item.params | default('') }}" + state: "{{ item.state | default('present') }}" + loop: "{{ tripleo_modules }}" + loop_control: + label: "{{ item.name }}" + when: + - modules_file.stat.exists | bool + - (modules_file.stat.isdir is defined) and + not (modules_file.stat.isdir | bool) diff --git a/tripleo_ansible/roles/tripleo-module-load/templates/module-load.conf.j2 b/tripleo_ansible/roles/tripleo-module-load/templates/module-load.conf.j2 new file mode 100644 index 000000000..21808b95f --- /dev/null +++ b/tripleo_ansible/roles/tripleo-module-load/templates/module-load.conf.j2 @@ -0,0 +1,2 @@ +# {{ ansible_managed }} +{{ item.name }} {{ item.params |default('') }} diff --git a/zuul.d/molecule.yaml b/zuul.d/molecule.yaml index 5c003789d..b91960b73 100644 --- a/zuul.d/molecule.yaml +++ b/zuul.d/molecule.yaml @@ -10,6 +10,7 @@ - tripleo-ansible-centos-7-molecule-tuned - tripleo-ansible-centos-7-role-addition - tripleo-ansible-centos-7-molecule-tripleo-create-admin + - tripleo-ansible-centos-7-molecule-tripleo-module-load gate: jobs: - tripleo-ansible-centos-7-molecule-aide @@ -20,6 +21,7 @@ - tripleo-ansible-centos-7-molecule-tuned - tripleo-ansible-centos-7-role-addition - tripleo-ansible-centos-7-molecule-tripleo-create-admin + - tripleo-ansible-centos-7-molecule-tripleo-module-load name: tripleo-ansible-molecule-jobs - job: files: @@ -44,7 +46,7 @@ tox_envlist: mol-test_json_error_callback - job: files: - - ^ansible_plugins/action/package.py + - ^tripleo_ansible/ansible_plugins/action/package.py - ^tripleo_ansible/roles/test_package_action/.* name: tripleo-ansible-centos-7-molecule-test_package_action parent: tripleo-ansible-centos @@ -81,3 +83,10 @@ timeout: 1800 vars: tox_envlist: mol-tripleo-create-admin +- job: + files: + - ^tripleo_ansible/roles/tripleo-module-load/.* + name: tripleo-ansible-centos-7-molecule-tripleo-module-load + parent: tripleo-ansible-centos + vars: + tox_envlist: mol-tripleo-module-load