guidugli.kernel_config
Ansible役割: kernel_config
RHEL/CentOS、Fedora、Debian/Ubuntuにsysctlをインストールし、設定するAnsibleの役割です。この役割では、カーネルモジュールを無効にしたり、ブラックリストに登録したり、自動起動に設定したりすることができます。また、電源管理に関連するUDEVルールを設定することもできます。
注意: カーネルモジュールを無効にしたり、デバイスをスリープ状態に設定する(udev設定)ことは、システムの動作に影響を与える可能性があり、システムの回復(シングルユーザーログインやライブブートが必要になる場合もあります)を要することがあります。
要件
ベアメタルまたはハイパーバイザー仮想化上で動作するオペレーティングシステム。この設定によって、この役割はコンテナ化されたシステムでは正しく動作しない場合があります。
役割の変数
利用可能な変数は以下に記載されており、デフォルト値も示します(defaults/main.yml
を参照):
kernel_disable_modules: ['cramfs', 'freevxfs', 'jjfs2', 'hfs', 'hfsplus', 'udf', 'squashfs',
'dccp', 'sctp', 'rds', 'tipc']
無効にすべきカーネルモジュールをリストするためにこの変数を使用します。usb-storageをリストに追加すると、USBストレージデバイスが機能しなくなりますので、USBGuardの使用を検討してください。デフォルトの値はほとんどのシステムで機能します。システムがこれらのモジュールの一部を使用する必要がある場合は、この変数を希望の設定で上書きしてください。
kernel_blacklist_modules: ['cramfs', 'freevxfs', 'jjfs2', 'hfs', 'hfsplus', 'udf', 'squashfs',
'dccp', 'sctp', 'rds', 'tipc']
ブラックリストに登録すべきモジュール。デフォルト値はほとんどのシステムで機能します。システムがこれらのモジュールの一部を使用する必要がある場合は、この変数を希望の設定で上書きしてください。
#kernel_autostart_modules: ['br_netfilter']
自動起動されるモジュール。
kernel_sysctl:
- { name: fs.suid_dumpable, value: "0" }
- { name: fs.protected_hardlinks, value: "1" }
- { name: fs.protected_symlinks, value: "1" }
- { name: fs.inotify.max_user_instances, value: "1024" }
- { name: kernel.dmesg_restrict, value: "1" }
- { name: kernel.yama.ptrace_scope, value: "1" }
- { name: kernel.randomize_va_space, value: "2" }
- { name: kernel.kptr_restrict, value: "1" }
- { name: kernel.nmi_watchdog, value: "0" }
- { name: net.ipv4.ip_forward, value: "0" }
- { name: net.ipv4.conf.all.forwarding, value: "0" }
- { name: net.ipv4.conf.all.send_redirects, value: "0" }
- { name: net.ipv4.conf.default.send_redirects, value: "0" }
- { name: net.ipv4.conf.all.accept_source_route, value: "0" }
- { name: net.ipv4.conf.default.accept_source_route, value: "0" }
- { name: net.ipv4.conf.all.accept_redirects, value: "0" }
- { name: net.ipv4.conf.default.accept_redirects, value: "0" }
- { name: net.ipv4.conf.all.secure_redirects, value: "0" }
- { name: net.ipv4.conf.default.secure_redirects, value: "0" }
- { name: net.ipv4.conf.all.log_martians, value: "1" }
- { name: net.ipv4.conf.default.log_martians, value: "1" }
- { name: net.ipv4.icmp_echo_ignore_broadcasts, value: "1" }
- { name: net.ipv4.icmp_ignore_bogus_error_responses, value: "1" }
- { name: net.ipv4.conf.all.rp_filter, value: "1" }
- { name: net.ipv4.conf.default.rp_filter, value: "1" }
- { name: net.ipv4.tcp_syncookies, value: "1" }
- { name: net.ipv6.conf.all.disable_ipv6, value: "1" }
- { name: net.ipv6.conf.default.disable_ipv6, value: "1" }
システムに設定するsysctlパラメータを指定します。デフォルト設定は、ルーターとして機能しないシステムおよびIPv6を使用しないシステムに有効です。ルールを確認し、必要に応じてこの変数を上書きしてください。
kernel_sysctl_flush_network_routes: yes
これをyesに設定すると、net.ipv4.route.flushとnet.ipv6.route.flushを1に設定し、再読み込みします。
#kernel_udev_sata_link_power_mgmt: med_power_with_dipm
SATAリンクの電源管理ポリシー。有効な値はmin_power、max_performance、medium_power、med_power_with_dipmです。
#kernel_udev_autosuspend_ahci_devices: yes
AHCIコントローラとATAデバイスを自動サスペンドします。
#kernel_udev_autosuspend_scsi_devices: yes
SCSIデバイスを自動サスペンドします。ドライバー=sd。
#kernel_udev_disable_bluetooth: no
Bluetoothを無効にします。
#kernel_udev_disable_wake_on_lan: yes
Wake on LANを無効にします。
#kernel_udev_usb_autosuspend_devices:
# - { vendor: '13fe', product: '5500' } # Silicon power flash drive
# - { vendor: '1532', product: '0f13', autosuspend: 120 } # キーボード
自動サスペンドするデバイスのリスト。 通常、LinuxはすでにUSBハブや他のデバイスに自動サスペンドを設定しているため、このオプションを使用する必要はありません。どのデバイスが自動サスペンドされているかどうかは、/sys/bus/usb/devices/*/power/controlを見て確認できます。
#kernel_udev_pci_autosuspend_devices:
# - { vendor: '0x8086', device: '0x0c00' }
# - { vendor: '0x8086', device: '0x0412' }
自動サスペンドするPCIデバイスのリスト。
#kernel_udev_enable_wlan_powersave: yes
WLANの省電力を有効にしますか?
以下の変数は、対象システムに対して変更する必要はありません(vars/main.yml
を参照):
kernel_udev_reload_cmd: "udevadm control --reload-rules && udevadm trigger"
udevルールを再読み込みするためのコマンド。
依存関係
依存関係はありません。
例のプレイブック
- hosts: servers
vars:
kernel_disable_modules: ['cramfs', 'freevxfs', 'jjfs2', 'hfs', 'hfsplus', 'udf', 'vfat', 'squashfs']
kernel_blacklist_modules: ['radeon', 'amdgpu']
kernel_sysctl:
- { name: net.ipv4.conf.all.forwarding, value: "0" }
- { name: net.ipv4.conf.all.send_redirects, value: "0" }
- { name: net.ipv4.conf.default.send_redirects, value: "0" }
- { name: net.ipv4.conf.all.accept_source_route, value: "0" }
- { name: net.ipv4.conf.default.accept_source_route, value: "0" }
- { name: net.ipv4.conf.all.accept_redirects, value: "0" }
- { name: net.ipv4.conf.default.accept_redirects, value: "0" }
- { name: net.ipv4.conf.all.secure_redirects, value: "0" }
- { name: net.ipv4.conf.default.secure_redirects, value: "0" }
- { name: net.ipv4.conf.all.log_martians, value: "1" }
- { name: net.ipv4.conf.default.log_martians, value: "1" }
- { name: net.ipv4.icmp_echo_ignore_broadcasts, value: "1" }
- { name: net.ipv4.icmp_ignore_bogus_error_responses, value: "1" }
- { name: net.ipv4.conf.all.rp_filter, value: "1" }
- { name: net.ipv4.conf.default.rp_filter, value: "1" }
- { name: net.ipv4.tcp_syncookies, value: "1" }
kernel_sysctl_flush_network_routes: yes
roles:
- { role: guidugli.kernel_config }
ライセンス
MIT / BSD
著者情報
この役割は2020年にCarlos Guidugliによって作成されました。