Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore idempotency for disabling unused filesystems with Ansible 2.16.0 #718

Merged

Conversation

akikanellis
Copy link
Contributor

@akikanellis akikanellis commented Nov 19, 2023

The os_unused_filesystems was lacking sorting, making the task not idempotent. This was especially apparent and random in Molecule tests when this collection was added as a dependency.

Signed-off-by: Aki Kanellis hello@akikanellis.com

The `os_unused_filesystems` was lacking sorting, making the task not
idempotent. This was especially apparent and random in Molecule tests
when this collection was added as a dependency.

Signed-off-by: Aki Kanellis <hello@akikanellis.com>
@schurzi
Copy link
Contributor

schurzi commented Nov 19, 2023

Thanks for submitting this. I am a bit puzzled, since we actually have idempotency tests which do not show this problem. Can you describe your test setup a bit more detailed?

@akikanellis
Copy link
Contributor Author

akikanellis commented Nov 20, 2023

Thanks for submitting this. I am a bit puzzled, since we actually have idempotency tests which do not show this problem. Can you describe your test setup a bit more detailed?

@schurzi I first noticed the issue in my homelab project, which is using this collection here. That is quite a complicated setup, so I have created a minimal reproduction repo where you can see the issue reproduced both for Docker and Vagrant based molecule tests.

It does seem like the current test setup in this collection with molecule is somehow causing this randomness to not happen. I had a look but haven't figured it out yet. It would be good to figure it out so that we can add some additional test coverage and prevent this from happening in the future. I will let you know if I find anything.

Hope that helps.

@schurzi
Copy link
Contributor

schurzi commented Nov 20, 2023

So, after some debugging I was able to track this down. The task, that mixes up the list is:

- name: Remove used filesystems from fs-list
ansible.builtin.set_fact:
os_unused_filesystems: "{{ os_unused_filesystems | difference(ansible_mounts | map(attribute='fstype') | list) }}"

And I also discovered why our tests don't find this issue. It is a new behaviour in Ansible 2.16.0 introduced by ansible/ansible#81639. Our tests currently run against Ansible 2.15.6 and should update in the next few days, since Ansible 2.16.0 was released two weeka ago.

@akikanellis
Copy link
Contributor Author

That makes sense, thanks for looking into it. Is the solution here ok or is there a more preferable way to implement this? Happy to implement whatever is needed.

@schurzi
Copy link
Contributor

schurzi commented Nov 21, 2023

I think it is OK. I debated a bit if including the sort in the task, that shuffles the array, would be preferable, but in the end it makes almost no difference. Keeping it in the template will keep the order the same, even if we restructure our tasks, so I think this might be a better solution.

I want to fix our testing before merging this, working on it in #721. I expect this will work out today.

@schurzi schurzi added the bug label Nov 21, 2023
@schurzi schurzi changed the title Make disabling unused filesystems idempotent Restore idempotency for disabling unused filesystems with Ansible 2.16.0 Nov 21, 2023
@schurzi schurzi merged commit e98d766 into dev-sec:master Nov 21, 2023
36 of 37 checks passed
@schurzi
Copy link
Contributor

schurzi commented Nov 21, 2023

Many thanks! This was a very helpful PR and we all learned a lot :)

@akikanellis
Copy link
Contributor Author

Many thanks! This was a very helpful PR and we all learned a lot :)

Happy to have helped and thanks for the review!

@akikanellis akikanellis deleted the fix-disabling-filesystems-idempotency branch November 21, 2023 21:50
akikanellis added a commit to akikanellis/homelab that referenced this pull request Nov 25, 2023
We temporarily need to update to a git commit hash due to a fix that was committed but not released yet.
The commit fixes random test failures due to a lack of sorting in a task.

See: dev-sec/ansible-collection-hardening#718
akikanellis added a commit to akikanellis/homelab that referenced this pull request Nov 25, 2023
We temporarily need to update to a git commit hash due to a fix that was committed but not released yet.
The commit fixes random test failures due to a lack of sorting in a task.

See: dev-sec/ansible-collection-hardening#718
akikanellis added a commit to akikanellis/homelab that referenced this pull request Nov 25, 2023
We temporarily need to update to a git commit hash due to a fix that was committed but not released yet.
The commit fixes random test failures due to a lack of sorting in a task.

See: dev-sec/ansible-collection-hardening#718
@nejch
Copy link
Contributor

nejch commented Jan 19, 2024

@schurzi this fix would be useful for us as we test idempotence and it's currently blocking upgrading in our own downstream collection. Are there any plans for a release with this? Sorry, I know these types of pings are annoying 😅

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

Successfully merging this pull request may close these issues.

4 participants