community.general.parted 模块 – 配置块设备分区
注意
此模块是 community.general 集合 (版本 10.1.0) 的一部分。
如果您使用的是 ansible
包,则可能已经安装了此集合。它不包含在 ansible-core
中。要检查它是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install community.general
。您需要其他要求才能使用此模块,有关详细信息,请参阅 要求。
要在剧本中使用它,请指定:community.general.parted
。
概要
此模块允许使用
parted
命令行工具配置块设备分区。有关字段和选项的完整说明,请查看 GNU parted 手册。
要求
执行此模块的主机需要以下要求。
参数
参数 |
注释 |
---|---|
设置新创建分区的对齐方式。使用 选项
|
|
要操作的块设备(磁盘)。 也可以对常规文件进行分区,但建议使用 |
|
必须在分区上设置的标志列表。 |
|
如果指定且分区不存在,则会将文件系统类型设置为给定分区。 参数可选,但请参阅下面关于负 |
|
设置分区编号的名称(仅限 GPT、Mac、MIPS 和 PC98)。 |
|
受影响的分区号。 在对磁盘执行任何操作时(获取信息除外)都需要。 |
|
分区结束位置相对于磁盘起始位置的偏移量,也就是距离磁盘起始位置的“距离”。负数表示距离磁盘末尾的距离。 距离可以使用 parted 支持的所有单位(compat 除外),并且区分大小写,例如 默认值: |
|
分区起始位置相对于磁盘起始位置的偏移量,也就是距离磁盘起始位置的“距离”。负数表示距离磁盘末尾的距离。 距离可以使用 parted 支持的所有单位(compat 除外),并且区分大小写,例如 使用负值可能需要设置 默认值: |
|
只能与
选项
|
|
创建或删除分区。 如果设置为 选项
|
|
选择 Parted 用于显示磁盘位置和容量以及解释用户提供的(如果没有单位后缀)位置和容量的当前默认单位。 获取有关磁盘的信息时,建议始终指定单位。 选项
|
属性
属性 |
支持 |
描述 |
---|---|---|
支持:完全支持 |
可以在 |
|
支持:不支持 |
处于差异模式时,将返回有关已更改内容(或可能需要在 |
注释
注意
获取有关新磁盘的信息以及系统上安装的 parted 版本早于 3.1 版本时,模块将通过
/sys/
查询内核以获取磁盘信息。在这种情况下,不支持 CHS 和 CYL 单位。如果未给出
fs_type
,则会拒绝负part_start
起始值。此错误已在 parted 3.2.153 中修复。如果要使用负part_start
,也请指定fs_type
或确保您的系统包含较新的 parted。
示例
- name: Create a new ext4 primary partition
community.general.parted:
device: /dev/sdb
number: 1
state: present
fs_type: ext4
- name: Remove partition number 1
community.general.parted:
device: /dev/sdb
number: 1
state: absent
- name: Create a new primary partition with a size of 1GiB
community.general.parted:
device: /dev/sdb
number: 1
state: present
part_end: 1GiB
- name: Create a new primary partition for LVM
community.general.parted:
device: /dev/sdb
number: 2
flags: [ lvm ]
state: present
part_start: 1GiB
- name: Create a new primary partition with a size of 1GiB at disk's end
community.general.parted:
device: /dev/sdb
number: 3
state: present
fs_type: ext3
part_start: -1GiB
# Example on how to read info and reuse it in subsequent task
- name: Read device information (always use unit when probing)
community.general.parted: device=/dev/sdb unit=MiB
register: sdb_info
- name: Remove all partitions from disk
community.general.parted:
device: /dev/sdb
number: '{{ item.num }}'
state: absent
loop: '{{ sdb_info.partitions }}'
- name: Extend an existing partition to fill all available space
community.general.parted:
device: /dev/sdb
number: "{{ sdb_info.partitions | length }}"
part_end: "100%"
resize: true
state: present
返回值
常见返回值已在此处记录,以下是此模块独有的字段
键 |
描述 |
---|---|
当前分区信息 返回:成功 示例: |
|
通用设备信息。 返回:成功 |
|
设备分区的列表。 返回:成功 |
|
模块执行的 parted 脚本 返回:成功 |