diff --git a/doc/source/roles/role-tripleo-kernel.rst b/doc/source/roles/role-tripleo-kernel.rst new file mode 100644 index 000000000..8be21e96a --- /dev/null +++ b/doc/source/roles/role-tripleo-kernel.rst @@ -0,0 +1,6 @@ +===================== +Role - tripleo-kernel +===================== + +.. ansibleautoplugin:: + :role: tripleo_ansible/roles/tripleo-kernel diff --git a/tripleo_ansible/roles/tripleo-kernel/defaults/main.yml b/tripleo_ansible/roles/tripleo-kernel/defaults/main.yml new file mode 100644 index 000000000..3bd4a3bd8 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-kernel/defaults/main.yml @@ -0,0 +1,20 @@ +--- +# 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. +tripleo_kernel_extra_modules: {} +tripleo_kernel_sysctl_extra_settings: {} diff --git a/tripleo_ansible/roles/tripleo-kernel/handlers/main.yml b/tripleo_ansible/roles/tripleo-kernel/handlers/main.yml new file mode 100644 index 000000000..4e7788ef9 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-kernel/handlers/main.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: Sysctl reload + become: true + systemd: + name: systemd-sysctl.service + state: restarted + +- name: Modules reload + become: true + systemd: + name: systemd-modules-load.service + state: restarted diff --git a/tripleo_ansible/roles/tripleo-kernel/meta/main.yml b/tripleo_ansible/roles/tripleo-kernel/meta/main.yml new file mode 100644 index 000000000..0532df8b9 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-kernel/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-kernel + 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-kernel/molecule/default/Dockerfile b/tripleo_ansible/roles/tripleo-kernel/molecule/default/Dockerfile new file mode 100644 index 000000000..1b91a0e0b --- /dev/null +++ b/tripleo_ansible/roles/tripleo-kernel/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-kernel/molecule/default/molecule.yml b/tripleo_ansible/roles/tripleo-kernel/molecule/default/molecule.yml new file mode 100644 index 000000000..7409d6b75 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-kernel/molecule/default/molecule.yml @@ -0,0 +1,54 @@ +--- +driver: + name: delegated + options: + managed: false + login_cmd_template: >- + ssh + -o UserKnownHostsFile=/dev/null + -o StrictHostKeyChecking=no + -o Compression=no + -o TCPKeepAlive=yes + -o VerifyHostKeyDNS=no + -o ForwardX11=no + -o ForwardAgent=no + {instance} + ansible_connection_options: + ansible_connection: ssh + +log: true + +platforms: + - name: instance + +provisioner: + name: ansible + config_options: + defaults: + fact_caching: jsonfile + fact_caching_connection: /tmp/molecule/facts + inventory: + hosts: + all: + hosts: + instance: + ansible_host: localhost + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_ROLES_PATH: "${ANSIBLE_ROLES_PATH}:${HOME}/zuul-jobs/roles" + +scenario: + name: default + test_sequence: + - prepare + - converge + - verify + +lint: + enabled: false + +verifier: + name: testinfra + lint: + name: flake8 diff --git a/tripleo_ansible/roles/tripleo-kernel/molecule/default/playbook.yml b/tripleo_ansible/roles/tripleo-kernel/molecule/default/playbook.yml new file mode 100644 index 000000000..ab52db833 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-kernel/molecule/default/playbook.yml @@ -0,0 +1,21 @@ +--- +# 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-kernel" diff --git a/tripleo_ansible/roles/tripleo-kernel/molecule/default/prepare.yml b/tripleo_ansible/roles/tripleo-kernel/molecule/default/prepare.yml new file mode 100644 index 000000000..ef85c3128 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-kernel/molecule/default/prepare.yml @@ -0,0 +1,21 @@ +--- +# 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 diff --git a/tripleo_ansible/roles/tripleo-kernel/molecule/extra/Dockerfile b/tripleo_ansible/roles/tripleo-kernel/molecule/extra/Dockerfile new file mode 100644 index 000000000..1b91a0e0b --- /dev/null +++ b/tripleo_ansible/roles/tripleo-kernel/molecule/extra/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-kernel/molecule/extra/molecule.yml b/tripleo_ansible/roles/tripleo-kernel/molecule/extra/molecule.yml new file mode 100644 index 000000000..8e1b08153 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-kernel/molecule/extra/molecule.yml @@ -0,0 +1,54 @@ +--- +driver: + name: delegated + options: + managed: false + login_cmd_template: >- + ssh + -o UserKnownHostsFile=/dev/null + -o StrictHostKeyChecking=no + -o Compression=no + -o TCPKeepAlive=yes + -o VerifyHostKeyDNS=no + -o ForwardX11=no + -o ForwardAgent=no + {instance} + ansible_connection_options: + ansible_connection: ssh + +log: true + +platforms: + - name: instance + +provisioner: + name: ansible + config_options: + defaults: + fact_caching: jsonfile + fact_caching_connection: /tmp/molecule/facts + inventory: + hosts: + all: + hosts: + instance: + ansible_host: localhost + log: true + env: + ANSIBLE_STDOUT_CALLBACK: yaml + ANSIBLE_ROLES_PATH: "${ANSIBLE_ROLES_PATH}:${HOME}/zuul-jobs/roles" + +scenario: + name: extra + test_sequence: + - prepare + - converge + - verify + +lint: + enabled: false + +verifier: + name: testinfra + lint: + name: flake8 diff --git a/tripleo_ansible/roles/tripleo-kernel/molecule/extra/playbook.yml b/tripleo_ansible/roles/tripleo-kernel/molecule/extra/playbook.yml new file mode 100644 index 000000000..10e8c9645 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-kernel/molecule/extra/playbook.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: Converge + hosts: all + roles: + - role: "tripleo-kernel" + tripleo_kernel_extra_modules: + - dummy: {} + tripleo_kernel_sysctl_extra_settings: + kernel.ftrace_dump_on_oops: + value: 1 diff --git a/tripleo_ansible/roles/tripleo-kernel/molecule/extra/prepare.yml b/tripleo_ansible/roles/tripleo-kernel/molecule/extra/prepare.yml new file mode 100644 index 000000000..ef85c3128 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-kernel/molecule/extra/prepare.yml @@ -0,0 +1,21 @@ +--- +# 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 diff --git a/tripleo_ansible/roles/tripleo-kernel/tasks/main.yml b/tripleo_ansible/roles/tripleo-kernel/tasks/main.yml new file mode 100644 index 000000000..c23f8f47d --- /dev/null +++ b/tripleo_ansible/roles/tripleo-kernel/tasks/main.yml @@ -0,0 +1,47 @@ +--- +# 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-kernel" will search for and load any operating system variable file + +- name: Kernel tuning block + become: true + block: + - name: Set default sysctl options + template: + src: "tripleo-sysctl.conf.j2" + dest: "/etc/sysctl.d/99-tripleo.conf" + notify: + - Sysctl reload + + - name: Set extra sysctl options + sysctl: + name: "{{ item.key }}" + value: "{{ item.opt.value }}" + sysctl_set: "{{ item.opt.set | default(true) }}" + state: "{{ item.opt.state | default('present') }}" + sysctl_file: "/etc/sysctl.d/99-tripleo.conf" + reload: false + loop: "{{ tripleo_kernel_sysctl_extra_settings | dict2items(key_name='key', value_name='opt') }}" + notify: + - Sysctl reload + + - name: Write list of modules to load at boot + template: + src: "tripleo-modprobe.conf.j2" + dest: "/etc/modules-load.d/99-tripleo.conf" + notify: + - Modules reload diff --git a/tripleo_ansible/roles/tripleo-kernel/templates/tripleo-modprobe.conf.j2 b/tripleo_ansible/roles/tripleo-kernel/templates/tripleo-modprobe.conf.j2 new file mode 100644 index 000000000..e6746bcdf --- /dev/null +++ b/tripleo_ansible/roles/tripleo-kernel/templates/tripleo-modprobe.conf.j2 @@ -0,0 +1,5 @@ +# {{ ansible_managed }} + +{% for item in tripleo_kernel_modules | combine(tripleo_kernel_extra_modules) | dict2items(key_name='key', value_name='opt') %} +{{ item.key }} +{% endfor %} diff --git a/tripleo_ansible/roles/tripleo-kernel/templates/tripleo-sysctl.conf.j2 b/tripleo_ansible/roles/tripleo-kernel/templates/tripleo-sysctl.conf.j2 new file mode 100644 index 000000000..32c539121 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-kernel/templates/tripleo-sysctl.conf.j2 @@ -0,0 +1,5 @@ +# {{ ansible_managed }} + +{% for item in tripleo_kernel_sysctl_settings | dict2items(key_name='key', value_name='opt') %} +{{ item.key }} = {{ item.opt.value }} +{% endfor %} diff --git a/tripleo_ansible/roles/tripleo-kernel/vars/main.yml b/tripleo_ansible/roles/tripleo-kernel/vars/main.yml new file mode 100644 index 000000000..06139e332 --- /dev/null +++ b/tripleo_ansible/roles/tripleo-kernel/vars/main.yml @@ -0,0 +1,71 @@ +--- +# 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_kernel_modules: + nf_conntrack: {} + +tripleo_kernel_sysctl_settings: + net.ipv4.tcp_keepalive_intvl: + value: 1 + net.ipv4.tcp_keepalive_probes: + value: 5 + net.ipv4.tcp_keepalive_time: + value: 5 + net.ipv4.conf.default.send_redirects: + value: 0 + net.ipv4.conf.all.send_redirects: + value: 0 + net.ipv4.conf.all.arp_accept: + value: 1 + net.ipv4.conf.default.accept_redirects: + value: 0 + net.ipv4.conf.default.secure_redirects: + value: 0 + net.ipv4.conf.all.secure_redirects: + value: 0 + net.ipv4.conf.default.log_martians: + value: 1 + net.ipv4.conf.all.log_martians: + value: 1 + net.nf_conntrack_max: + value: 500000 + net.netfilter.nf_conntrack_max: + value: 500000 + net.ipv6.conf.lo.disable_ipv6: + value: 0 + net.ipv6.conf.all.accept_ra: + value: 0 + net.ipv6.conf.default.accept_ra: + value: 0 + net.ipv6.conf.all.autoconf: + value: 0 + net.ipv6.conf.default.autoconf: + value: 0 + net.ipv6.conf.default.accept_redirects: + value: 0 + net.ipv6.conf.all.accept_redirects: + value: 0 + net.ipv4.conf.all.arp_notify: + value: 1 + net.ipv6.conf.all.ndisc_notify: + value: 1 + net.core.netdev_max_backlog: + value: 10000 + kernel.dmesg_restrict: + value: 1 + fs.suid_dumpable: + value: 0 diff --git a/zuul.d/molecule.yaml b/zuul.d/molecule.yaml index f86136919..bb9a06d69 100644 --- a/zuul.d/molecule.yaml +++ b/zuul.d/molecule.yaml @@ -26,6 +26,7 @@ - tripleo-ansible-centos-7-molecule-tripleo-container-stop - tripleo-ansible-centos-7-molecule-tripleo-hieradata - tripleo-ansible-centos-7-molecule-tripleo-upgrade-hiera + - tripleo-ansible-centos-7-molecule-tripleo-kernel gate: jobs: - tripleo-ansible-centos-7-molecule-aide @@ -52,6 +53,7 @@ - tripleo-ansible-centos-7-molecule-tripleo-container-stop - tripleo-ansible-centos-7-molecule-tripleo-hieradata - tripleo-ansible-centos-7-molecule-tripleo-upgrade-hiera + - tripleo-ansible-centos-7-molecule-tripleo-kernel name: tripleo-ansible-molecule-jobs - job: files: @@ -227,3 +229,10 @@ parent: tripleo-ansible-centos-7-base vars: tripleo_role_name: tripleo-upgrade-hiera +- job: + files: + - ^tripleo_ansible/roles/tripleo-kernel/.* + name: tripleo-ansible-centos-7-molecule-tripleo-kernel + parent: tripleo-ansible-centos-7-base + vars: + tripleo_role_name: tripleo-kernel