community.crypto.luks_device 模块 – 管理加密 (LUKS) 设备
注意
此模块是 community.crypto 集合 (版本 2.22.3) 的一部分。
如果您使用的是 ansible
软件包,则可能已经安装了此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用: ansible-galaxy collection install community.crypto
。您需要其他要求才能使用此模块,有关详细信息,请参见 要求。
要在剧本中使用它,请指定: community.crypto.luks_device
。
概要
模块管理给定设备上的 LUKS。支持创建、销毁、打开和关闭 LUKS 容器,以及添加或删除新的密钥和密码。
要求
执行此模块的主机需要以下要求。
参数
参数 |
注释 |
---|---|
允许设备的丢弃 (也称为 TRIM) 请求。 仅在打开容器时使用。 选项
|
|
此选项允许用户为 LUKS 容器定义密码规范字符串。 仅在创建容器时使用。 对于 2.6.10 之前的内核,使用 |
|
要使用的设备(例如 |
|
如果设置为 注意,当从容器中删除最后一个密钥后,将无法再打开该容器! 选项
|
|
此选项允许用户指定在 LUKS 密钥设置方案和卷密钥摘要中使用的哈希函数。 仅在创建容器时使用。 |
|
用于解锁容器。大多数操作都需要 注意,使用明文密钥文件很危险。确保它们受到保护。 |
|
仅当 LUKS 容器不存在时设置密钥大小。 |
|
在 注意, |
|
当 |
|
向 注意,自 community.crypto 1.4.0 版本起,添加额外的密钥才是幂等的。对于旧版本,即使此密钥文件已存在于另一个密钥槽中,也会使用新的密钥槽。 注意,使用明文密钥文件很危险。确保它们受到保护。 |
|
将额外的 注意, |
|
向 注意,自 community.crypto 1.4.0 版本起,添加额外的密码才是幂等的。对于旧版本,即使此密码已存在于另一个密钥槽中,也会使用新的密钥槽。 |
|
用于解锁容器。大多数操作都需要 |
|
此选项允许用户配置使用的基于密码的密钥派生函数 (PBKDF)。 仅在创建容器时以及向现有容器添加密钥时使用。 |
|
要使用的算法。 仅适用于 LUKS 2 格式。 选项
|
|
指定 PBKDF 使用的迭代次数。 与 |
|
PBKDF 的内存成本限制(以千字节为单位)。 这不用于 PBKDF2,而仅用于 Argon PBKDF。 |
|
PBKDF 的并行成本。这是并行运行的线程数。 这不用于 PBKDF2,而仅用于 Argon PBKDF。 |
|
允许用户绕过 dm-crypt 内部工作队列并同步处理读取请求。 仅在打开容器时使用。 选项
|
|
允许用户绕过 dm-crypt 内部工作队列并同步处理写入请求。 仅在打开容器时使用。 选项
|
|
允许用户使用提交 IO 的同一 CPU 执行加密。 默认情况下使用无绑定工作队列,以便在可用 CPU 之间自动平衡加密工作。 仅在打开容器时使用。 选项
|
|
允许用户在加密后禁用将写入卸载到单独的线程。 在某些情况下,将块写入 IO 操作从加密线程卸载到单个线程会显著降低性能。 默认情况下,将块写入 IO 操作卸载到同一线程。 仅在打开容器时使用。 选项
|
|
允许用户将选项持久存储到容器的元数据中,并在下次自动使用它们。只有 仅适用于 LUKS2 容器。 仅在打开容器时使用。 选项
|
|
从 注意,自 community.crypto 1.4.0 版本起,删除密钥才是幂等的。对于旧版本,尝试删除不再存在的密钥会导致错误。 注意,要从 LUKS 容器中删除最后一个密钥,必须将 注意,使用明文密钥文件很危险。确保它们受到保护。 |
|
删除 注意, 注意,给定的 |
|
从 注意,移除密码短语的操作只有从 community.crypto 1.4.0 版本开始才具有幂等性。对于旧版本,尝试移除不再存在的密码短语会导致错误。 注意,要从 LUKS 容器中移除最后一个密钥槽,必须将 |
|
此选项允许用户指定用于 LUKS2 容器的扇区大小(以字节为单位)。 仅在创建容器时使用。 |
|
LUKS 容器的所需状态。根据其值,在给定设备上创建、销毁、打开或关闭 LUKS 容器。
选项
|
|
此选项允许用户显式定义想要使用的 LUKS 容器格式。选项为 选项
|
|
属性
属性 |
支持 |
描述 |
---|---|---|
支持:完全支持 |
可以在 |
|
支持:不支持 |
在 diff 模式下,将返回有关已更改内容(或可能需要在 |
示例
- name: Create LUKS container (remains unchanged if it already exists)
community.crypto.luks_device:
device: "/dev/loop0"
state: "present"
keyfile: "/vault/keyfile"
- name: Create LUKS container with a passphrase
community.crypto.luks_device:
device: "/dev/loop0"
state: "present"
passphrase: "foo"
- name: Create LUKS container with specific encryption
community.crypto.luks_device:
device: "/dev/loop0"
state: "present"
cipher: "aes"
hash: "sha256"
- name: (Create and) open the LUKS container; name it "mycrypt"
community.crypto.luks_device:
device: "/dev/loop0"
state: "opened"
name: "mycrypt"
keyfile: "/vault/keyfile"
- name: Close the existing LUKS container "mycrypt"
community.crypto.luks_device:
state: "closed"
name: "mycrypt"
- name: Make sure LUKS container exists and is closed
community.crypto.luks_device:
device: "/dev/loop0"
state: "closed"
keyfile: "/vault/keyfile"
- name: Create container if it does not exist and add new key to it
community.crypto.luks_device:
device: "/dev/loop0"
state: "present"
keyfile: "/vault/keyfile"
new_keyfile: "/vault/keyfile2"
- name: Add new key to the LUKS container (container has to exist)
community.crypto.luks_device:
device: "/dev/loop0"
keyfile: "/vault/keyfile"
new_keyfile: "/vault/keyfile2"
- name: Add new passphrase to the LUKS container
community.crypto.luks_device:
device: "/dev/loop0"
keyfile: "/vault/keyfile"
new_passphrase: "foo"
- name: Remove existing keyfile from the LUKS container
community.crypto.luks_device:
device: "/dev/loop0"
remove_keyfile: "/vault/keyfile2"
- name: Remove existing passphrase from the LUKS container
community.crypto.luks_device:
device: "/dev/loop0"
remove_passphrase: "foo"
- name: Completely remove the LUKS container and its contents
community.crypto.luks_device:
device: "/dev/loop0"
state: "absent"
- name: Create a container with label
community.crypto.luks_device:
device: "/dev/loop0"
state: "present"
keyfile: "/vault/keyfile"
label: personalLabelName
- name: Open the LUKS container based on label without device; name it "mycrypt"
community.crypto.luks_device:
label: "personalLabelName"
state: "opened"
name: "mycrypt"
keyfile: "/vault/keyfile"
- name: Close container based on UUID
community.crypto.luks_device:
uuid: 03ecd578-fad4-4e6c-9348-842e3e8fa340
state: "closed"
name: "mycrypt"
- name: Create a container using luks2 format
community.crypto.luks_device:
device: "/dev/loop0"
state: "present"
keyfile: "/vault/keyfile"
type: luks2
- name: Create a container with key in slot 4
community.crypto.luks_device:
device: "/dev/loop0"
state: "present"
keyfile: "/vault/keyfile"
keyslot: 4
- name: Add a new key in slot 5
community.crypto.luks_device:
device: "/dev/loop0"
keyfile: "/vault/keyfile"
new_keyfile: "/vault/keyfile"
new_keyslot: 5
- name: Remove the key from slot 4 (given keyfile must not be slot 4)
community.crypto.luks_device:
device: "/dev/loop0"
keyfile: "/vault/keyfile"
remove_keyslot: 4
返回值
常见返回值已在此处记录,以下是此模块特有的字段
密钥 (Key) |
描述 |
---|---|
当 返回:成功 示例: |