linux-system-roles.bootloader

启动程序

ansible-lint.yml ansible-test.yml codeql.yml markdownlint.yml python-unit-test.yml tft.yml tft_citest_bad.yml woke.yml

一个用于启动程序和内核命令行管理的 Ansible 角色。

支持的架构

该角色当前支持配置 grub2 启动程序,适用于以下架构:

  • AMD 和 Intel 64 位架构(x86-64)
  • 64 位 ARM 架构(ARMv8.0)
  • IBM Power 系统,小端(POWER9)

需求

请见以下内容

集合要求

如果您不想管理 ostree 系统,则该角色没有任何要求。

如果您想管理 ostree 系统,那么该角色需要额外的模块来自外部集合。请使用以下命令进行安装:

ansible-galaxy collection install -vv -r meta/collection-requirements.yml

角色变量

bootloader_gather_facts

是否收集包含所有内核启动信息的 bootloader_facts

默认值:false

类型:bool

bootloader_settings

使用此变量列出要设置的内核及其命令行参数。

必需键:

  1. kernel - 用于指定要更新设置的内核。每个列表应使用一个或多个键指定相同的内核。

    如果要添加一个内核,必须指定三个键 - path, title, initrd

    如果要修改或删除一个内核,可以指定一个或多个键。

    也可以指定 DEFAULTALL 来更新默认内核或所有内核。

    可用的键:

    • path - 内核路径
    • index - 内核索引
    • title - 内核标题
    • initrd - 内核 initrd 镜像

    可用的字符串:

    • DEFAULT - 更新默认条目
    • ALL - 更新所有条目
  2. state - 内核的状态。

    可用值:present, absent

    默认值:present

  3. options - 使用此参数指定要更新的设置。

    • name - 设置的名称。使用 replaced 时省略 name
    • value - 设置的值。若设置没有值,则必须省略 value,例如 quiet
    • state - present(默认)或 absent。值 absent 表示删除名为 name 的设置 - 必须提供名称。
    • previous - 可选 - 唯一值为 replaced - 用于指定以前的设置应被给定的设置替代。
    • copy_default - 可选 - 当创建内核时,可以指定 copy_default: true 以将默认参数复制到创建的内核。

有关示例,请参见 示例剧本

默认值:{}

类型:dict

bootloader_timeout

使用此变量可以自定义 GRUB 启动程序的加载时间。

默认值:5

类型:int

bootloader_password

使用此变量可以通过密码保护启动参数。

警告: 更改启动程序密码是不可幂等的。

启动程序用户名始终为 root

该值应来自加密存储。

如果未设置,则当前配置不受影响。

默认值:null

类型:string

bootloader_remove_password

将此变量设置为 true 可以移除启动程序密码。

默认值:false

类型:bool

bootloader_reboot_ok

如果为 true,当角色检测到需要重启以生效的更改时,角色将重启管理主机。

如果为 false,则由您决定何时重启管理主机。

角色将返回变量 bootloader_reboot_required(见下文),值为 true,表示发生了一些更改需要重启以生效。

默认值:false

类型:bool

角色导出的变量

该角色导出以下变量:

bootloader_reboot_needed

默认值 false - 如果为 true,则表示需要重启以应用角色所做的更改。

bootloader_facts

包含所有内核的启动信息。

当您设置 bootloader_gather_facts: true 时,角色将返回此变量。

示例:

"bootloader_facts": [
    {
        "args": "ro rootflags=subvol=root rd.luks.uuid=luks-9da1fdf5-14ac-49fd-a388-8b1ee48f3df1 rhgb quiet",
        "id": "luks-9da1fdf5-14ac-49fd-a388-8b1ee48f3df1 rhgb quiet",
        "index": "3",
        "initrd": "/boot/initramfs-0-rescue-c44543d15b2c4e898912c2497f734e67.img",
        "kernel": "/boot/vmlinuz-0-rescue-c44543d15b2c4e898912c2497f734e67",
        "root": "UUID=65c70529-e9ad-4778-9001-18fe8c525285",
        "title": "Fedora Linux (0-rescue-c44543d15b2c4e898912c2497f734e67) 36 (Workstation Edition)",
        "default": True
    },
    ...
]

示例剧本

- hosts: all
  vars:
    bootloader_settings:
      # 使用路径更新现有内核并替换以前的设置
      - kernel:
          path: /boot/vmlinuz-6.5.7-100.fc37.x86_64
        options:
          - name: console
            value: tty0
            state: present
          - previous: replaced
      # 使用索引更新现有内核
      - kernel:
          index: 1
        options:
          - name: print-fatal-signals
            value: 1
      # 使用标题更新现有内核
      - kernel:
          title: 红帽企业 Linux (4.1.1.1.el8.x86_64) 8
        options:
          - name: no_timer_check
        state: present
      # 添加一个带参数的内核
      - kernel:
          path: /boot/vmlinuz-6.5.7-100.fc37.x86_64
          initrd: /boot/initramfs-6.5.7-100.fc37.x86_64.img
          title: 我的内核
        options:
          - name: console
            value: tty0
          - name: print-fatal-signals
            value: 1
          - name: no_timer_check
            state: present
        state: present
      # 添加一个带参数并复制默认参数的内核
      - kernel:
          path: /boot/vmlinuz-6.5.7-100.fc37.x86_64
          initrd: /boot/initramfs-6.5.7-100.fc37.x86_64.img
          title: 我的内核
        options:
          - name: console
            value: tty0
          - copy_default: true
        state: present
      # 移除一个内核
      - kernel:
          title: 我的内核
        state: absent
      # 更新所有内核
      - kernel: ALL
        options:
          - name: debug
            state: present
      # 更新默认内核
      - kernel: DEFAULT
        options:
          - name: quiet
            state: present
    bootloader_timeout: 5
    bootloader_password: null
    bootloader_remove_password: false
    bootloader_reboot_ok: true
  roles:
    - linux-system-roles.bootloader

rpm-ostree

请参见 README-ostree.md

许可证

MIT

安装
ansible-galaxy install linux-system-roles.bootloader
许可证
mit
下载
82.9k