Skip to content

Conversation

@tomhesse
Copy link
Contributor

@tomhesse tomhesse commented May 16, 2025

SUMMARY

Create, destroy, and modify ZFS zpools and their vdev layouts, pool properties, and filesystem properties.

Closes #10123.

ISSUE TYPE
  • New Module/Plugin Pull Request
COMPONENT NAME

zpool

ADDITIONAL INFORMATION

If any changes are necessary, please let me know.

@ansibullbot ansibullbot added module module new_contributor Help guide this first time contributor plugins plugin (any type) labels May 16, 2025
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels May 16, 2025
@ansibullbot ansibullbot removed the ci_verified Push fixes to PR branch to re-run CI label May 16, 2025
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added the ci_verified Push fixes to PR branch to re-run CI label May 16, 2025
@ansibullbot ansibullbot removed the ci_verified Push fixes to PR branch to re-run CI label May 16, 2025
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-10 Automatically create a backport for the stable-10 branch labels May 16, 2025
@ansibullbot ansibullbot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label May 17, 2025
@felixfontein felixfontein removed the backport-10 Automatically create a backport for the stable-10 branch label May 24, 2025
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! I've added some first comments below. Please note that you also need to add tests.

@ansibullbot ansibullbot added the stale_ci CI is older than 7 days, rerun before merging label May 24, 2025
Copy link
Collaborator

@russoz russoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @tomhesse, thanks for your contribution.

There are some adjustments needed, but the general structure seems good.

You might want to consider using CmdRunner to run the commands. See https://docs.ansible.com/ansible/latest/collections/community/general/docsite/guide_cmdrunner.html for more details.

And if you use VarDict (see https://docs.ansible.com/ansible/latest/collections/community/general/docsite/guide_vardict.html for that one), the management of diff output is super straightforward.

Finally, please bear in mind that new modules are required to come with tests (either unit tests or integration tests - the latter is preferred, but the former is accepted).

@ansibullbot ansibullbot removed the stale_ci CI is older than 7 days, rerun before merging label May 29, 2025
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added the ci_verified Push fixes to PR branch to re-run CI label May 29, 2025
@ansibullbot ansibullbot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label May 30, 2025
---
zpool_single_disk_config:
- file: /tmp/disk0.img
loop: /dev/loop89
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, on Alpine you can only use /dev/loop0 up to /dev/loop7. Anything else does not work. Might be best to skip Alpine for now as well...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(You can run mknod -m660 /dev/loopX b 7 X to create /dev/loopX; if you do that in a loop for all devices not there yet, then it should work fine I guess...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the module to allow usage of files I realized this is probably better that setting up loop devices. This is probably the more convenient way.

@ansibullbot ansibullbot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Jun 2, 2025
Copy link
Collaborator

@russoz russoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @tomhesse, thanks for the updates so far, it is looking good.

I got a couple of few other comments here, but other than that is is looking good indeed. Cheers

role=dict(
type='str',
choices=['log', 'cache', 'spare', 'dedup', 'special'],
required=False,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required=False is redundant in the arg_spec, please remove it here and in the other options as well

- List of device paths to include in this vdev.
required: true
type: list
elements: str
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are paths, right? If they are always paths, then use:

Suggested change
elements: str
elements: path

(and adjust accordingly in the arg spec down below)

Comment on lines 227 to 239
rc, stdout, stderr = ctx.run(
subcommand='create',
disable_new_features=self.disable_new_features,
force=self.force,
dry_run=self.module.check_mode,
pool_properties=self.pool_properties,
filesystem_properties=self.filesystem_properties,
mountpoint=self.mountpoint,
altroot=self.altroot,
temp_name=self.temp_name,
name=self.name,
vdevs=self.vdevs,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CmdRunner receives the reference to the module => the arguments that are named and mapped straight into module parameters do not need to be passed in the run() call. I haven't verified thoroughly, but I think you could make this:

Suggested change
rc, stdout, stderr = ctx.run(
subcommand='create',
disable_new_features=self.disable_new_features,
force=self.force,
dry_run=self.module.check_mode,
pool_properties=self.pool_properties,
filesystem_properties=self.filesystem_properties,
mountpoint=self.mountpoint,
altroot=self.altroot,
temp_name=self.temp_name,
name=self.name,
vdevs=self.vdevs,
)
rc, stdout, stderr = ctx.run(subcommand='create')

Maybe some other additional parameters here needs declaring, but the majority there can be skipped. ;-)

Comment on lines 6 to 27
zpool_single_disk_config:
- /tmp/disk0.img

zpool_mirror_disk_config:
- /tmp/disk1.img
- /tmp/disk2.img

zpool_raidz_disk_config:
- /tmp/disk3.img
- /tmp/disk4.img

zpool_vdevs_disk_config:
vdev1:
- /tmp/disk5.img
vdev2:
- /tmp/disk6.img
vdev3:
- /tmp/disk7.img
- /tmp/disk8.img
vdev4:
- /tmp/disk9.img
- /tmp/disk10.img
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a good practice I would recommend you use remote_tmp_dir (see other integration tests, for example run git grep remote_tmp_dir tests/integration/targets/snap/) instead of /tmp.

@russoz
Copy link
Collaborator

russoz commented Jun 4, 2025

This PR fixes #10123

Copy link
Collaborator

@russoz russoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Jun 7, 2025
@felixfontein felixfontein merged commit 9286227 into ansible-collections:main Jun 7, 2025
110 checks passed
@felixfontein
Copy link
Collaborator

@tomhesse thanks for your contribution!
@russoz thanks for reviewing!

@mhalano
Copy link
Contributor

mhalano commented Jun 7, 2025

@tomhesse You have my sword, my friend. Thanks!

@tomhesse tomhesse deleted the zpool branch June 8, 2025 06:23
vbotka pushed a commit to vbotka/community.general that referenced this pull request Jun 10, 2025
* Add zpool module

* Add botmeta

* Use str.format instead of f-strings

* Remove nonlocal usage

* Add check to only pass ashift to zpool add

* Extend ansible_spec and remove unnecessary validation

* Apply suggestions and fix style

* Fix indentation of yaml lists

* Add method to normalize vdevs

Fix role: none in vdevs

* Use CmdRunner instead of run_command

* Fix styling and documentation

* Use str.format instead of f-strings

* Make sure vdevs are only required when state is present

* Add support for loop devices and normalize vdev type

* Add integration tests

* Add missing test dependencies for alpine and redhat

* Skip integration tests on rhel10 until there there packages available

* Use package module for better auto detection of package manager on rhel

* Add copyright header

* Skip tests on rhel and remove redhat install requirements

* Ensure loop devices under /dev exist

* Enable usage of files as pool devices

* Remove disk setup

* Use files as disks

* Apply suggestions

* Fix argument_spec
shinuza pushed a commit to shinuza/community.general that referenced this pull request Jul 22, 2025
* Add zpool module

* Add botmeta

* Use str.format instead of f-strings

* Remove nonlocal usage

* Add check to only pass ashift to zpool add

* Extend ansible_spec and remove unnecessary validation

* Apply suggestions and fix style

* Fix indentation of yaml lists

* Add method to normalize vdevs

Fix role: none in vdevs

* Use CmdRunner instead of run_command

* Fix styling and documentation

* Use str.format instead of f-strings

* Make sure vdevs are only required when state is present

* Add support for loop devices and normalize vdev type

* Add integration tests

* Add missing test dependencies for alpine and redhat

* Skip integration tests on rhel10 until there there packages available

* Use package module for better auto detection of package manager on rhel

* Add copyright header

* Skip tests on rhel and remove redhat install requirements

* Ensure loop devices under /dev exist

* Enable usage of files as pool devices

* Remove disk setup

* Use files as disks

* Apply suggestions

* Fix argument_spec
@SandiyosDev
Copy link

SandiyosDev commented Sep 28, 2025

Adding some feedback from #10771 and #10744, as get_current_layout in class Zpool of this module is not currently idempotent when some users are using symlinked persistent device names

Some users uses /dev/disk/by-id/... paths for vdevs which is best practice; on the first run, state: present does create the pool, but on second run, this module would compare /dev/disk/by-id/ paths with real paths /dev/sdX or /dev/nvmeXnXpX returned by zpool status, which would find a mismatch, then incorrectly tries to zpool add existing disks to the pool, which fails and shows-
eg /dev/disk/by-id/nvme-Samsung_SSD_980_PRO_1TB_SERIAL is in use and contains a unknown filesystem.

@felixfontein
Copy link
Collaborator

@SandiyosDev please check out #11020.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration tests/integration module module new_contributor Help guide this first time contributor plugins plugin (any type) tests tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zpool module

6 participants