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 <kecarter@redhat.com>
changes/68/666468/3
Kevin Carter 4 years ago
parent 56a6e8cbe8
commit a503857209
No known key found for this signature in database
GPG Key ID: CE94BD890A47B20A
  1. 31
      doc/source/roles/role-tripleo-module-load.rst
  2. 2
      role-addition.yml
  3. 18
      tox.ini
  4. 38
      tripleo_ansible/roles/tripleo-module-load/defaults/main.yml
  5. 44
      tripleo_ansible/roles/tripleo-module-load/meta/main.yml
  6. 37
      tripleo_ansible/roles/tripleo-module-load/molecule/default/Dockerfile
  7. 68
      tripleo_ansible/roles/tripleo-module-load/molecule/default/molecule.yml
  8. 23
      tripleo_ansible/roles/tripleo-module-load/molecule/default/playbook.yml
  9. 26
      tripleo_ansible/roles/tripleo-module-load/molecule/default/prepare.yml
  10. 15
      tripleo_ansible/roles/tripleo-module-load/molecule/default/verify.yml
  11. 37
      tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/Dockerfile
  12. 68
      tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/molecule.yml
  13. 27
      tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/playbook.yml
  14. 26
      tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/prepare.yml
  15. 15
      tripleo_ansible/roles/tripleo-module-load/molecule/remove_module/verify.yml
  16. 76
      tripleo_ansible/roles/tripleo-module-load/tasks/main.yml
  17. 2
      tripleo_ansible/roles/tripleo-module-load/templates/module-load.conf.j2
  18. 11
      zuul.d/molecule.yaml

@ -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.

@ -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

@ -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

@ -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([]) }}"

@ -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: []

@ -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"]

@ -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

@ -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

@ -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

@ -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.

@ -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"]

@ -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

@ -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

@ -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

@ -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.

@ -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)

@ -0,0 +1,2 @@
# {{ ansible_managed }}
{{ item.name }} {{ item.params |default('') }}

@ -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

Loading…
Cancel
Save