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

Update VirtualBox Group parsing to align with documentation. #8510

Merged

Conversation

lyrandy
Copy link
Contributor

@lyrandy lyrandy commented Jun 15, 2024

Previously, we could separate the group string on the / char and consider each element to be distinct, top-level groups. This change implements the notion of nested groups and the use of the , char to split multiple groups.

SUMMARY

Fixes #8508
Update the parsing algorithm in the VirtualBox dynamic inventory. The update changes how groups are formed when considering VirtualBox VMs.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

virtualbox inventory plugin

ADDITIONAL INFORMATION

Before, we would split groups based only on the / characters to form top-level groups. This was problematic for users (like me) who want to use nested groups for better variable management.

This change introduces the ability to use nested groups using /, and different groups using ,. This approach more closely aligns with the official VirtualBox documentation.

https://www.virtualbox.org/manual/UserManual.html#gui-vmgroups

In the linked issue, it shows that previously, the my_custom_variable would resolve to "This is in \"zgroup1\" group" because the groups for vm-1 are on "the same level", and so variable resolution depends on lexicographical ordering.
Also, groups for vm-2 had a trailing , character.

Here are the results of the Ansible debug commands with this updated inventory file.

ansible -i virtualbox.yml -m debug -a "var=my_custom_variable" all
vm-1 | SUCCESS => {
    "my_custom_variable": "This is in \"xgroup3\" group"
}
vm-2 | SUCCESS => {
    "my_custom_variable": "This is in \"all\" group"
}

ansible -i virtualbox.yml -m debug -a "var=group_names" all
vm-1 | SUCCESS => {
    "group_names": [
        "xgroup3",
        "ygroup2",
        "zgroup1"
    ]
}
vm-2 | SUCCESS => {
    "group_names": [
        "othergroup1",
        "othergroup2",
        "othergroup3"
    ]
}

Previously, we could separate the group string on the `/` char and
consider each element to be distinct, top-level groups. This change
implements the notion of nested groups and the use of the `,` char to
split multiple groups.
@ansibullbot

This comment was marked as resolved.

@ansibullbot ansibullbot added bug This issue/PR relates to a bug ci_verified Push fixes to PR branch to re-run CI inventory inventory plugin needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR new_contributor Help guide this first time contributor plugins plugin (any type) labels Jun 15, 2024
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-8 Automatically create a backport for the stable-8 branch backport-9 Automatically create a backport for the stable-9 branch breaking_change This PR contains a breaking change that MUST NOT be backported and removed backport-8 Automatically create a backport for the stable-8 branch backport-9 Automatically create a backport for the stable-9 branch labels Jun 15, 2024
@felixfontein
Copy link
Collaborator

Thanks for your contribution!

I'm pretty sure this is a new feature, and not a bugfix, since the documentation of the inventory plugin never mentioned the new behavior. It is a new feature, and (as you correctly stated in the changelog fragment) a breaking change. Breaking changes are not acceptable without a long enough deprecation period informing users of the changing behavior.

The best choice is to make the behavior configurable, with default being the old behavior. Then users who want can switch to the new behavior, and it isn't breaking anyone.

@felixfontein felixfontein removed the bug This issue/PR relates to a bug label Jun 15, 2024
@ansibullbot ansibullbot added the feature This issue/PR relates to a feature request label Jun 15, 2024
lyrandy added 2 commits June 16, 2024 23:23
Changed the implementation from a breaking change to a minor change by
introducing a new parameter to configure the behaviour. Keep the default
values to maintain the existing behaviour, and allow consumers an option
to opt-in.
The long lines were tripping CI. Reduce the length.
@ansibullbot ansibullbot removed 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 Jun 17, 2024
@ansibullbot ansibullbot added the stale_ci CI is older than 7 days, rerun before merging label Jun 25, 2024
changelogs/fragments/8508-virtualbox-inventory.yml Outdated Show resolved Hide resolved
plugins/inventory/virtualbox.py Outdated Show resolved Hide resolved
plugins/inventory/virtualbox.py Show resolved Hide resolved
plugins/inventory/virtualbox.py Outdated Show resolved Hide resolved
plugins/inventory/virtualbox.py Outdated Show resolved Hide resolved
Update documentation to match expected conventions and correct the final rendered formatting.
Set the initial parent_group to `None` instead of `all` and rely on the parent class' inventory reconciliation logic to ensure consistent behaviour across different inventory plugins.

Co-authored-by: Felix Fontein <felix@fontein.de>
@lyrandy
Copy link
Contributor Author

lyrandy commented Jun 28, 2024

Thank you for the great feedback Felix! I've taken in your suggestions.

@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR and removed stale_ci CI is older than 7 days, rerun before merging labels Jun 28, 2024
@lyrandy
Copy link
Contributor Author

lyrandy commented Jun 28, 2024

The tests did not like the line ending with the colon character.

- So, for a VM that's been configured using V(VBoxManage modifyvm "vm01" --groups "/TestGroup/TestGroup2,/TestGroup3"):
  C(TestGroup2) is a child group of C(TestGroup); 
  the VM will be part of C(TestGroup2) and C(TestGroup3).

I will reword it to avoid that stylistic choice.

One of the lines ended with a colon character which made the CI tests
fail since it would interpret it as a YAML key. Reworded the description
altogether to avoid that issue.
@ansibullbot ansibullbot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Jun 28, 2024
@felixfontein
Copy link
Collaborator

The tests did not like the line ending with the colon character.

- So, for a VM that's been configured using V(VBoxManage modifyvm "vm01" --groups "/TestGroup/TestGroup2,/TestGroup3"):
  C(TestGroup2) is a child group of C(TestGroup); 
  the VM will be part of C(TestGroup2) and C(TestGroup3).

That's basic YAML parsing which doesn't like it. A colon followed by a space indicates a dictionary entry in YAML, so you end up with a one-element dictionary with a funny key and value instead of having a string. Simply quoting the thing (or using things like >- etc.) prevents that.

Co-authored-by: Felix Fontein <felix@fontein.de>
@lyrandy
Copy link
Contributor Author

lyrandy commented Jul 11, 2024

The tests did not like the line ending with the colon character.

- So, for a VM that's been configured using V(VBoxManage modifyvm "vm01" --groups "/TestGroup/TestGroup2,/TestGroup3"):
  C(TestGroup2) is a child group of C(TestGroup); 
  the VM will be part of C(TestGroup2) and C(TestGroup3).

That's basic YAML parsing which doesn't like it. A colon followed by a space indicates a dictionary entry in YAML, so you end up with a one-element dictionary with a funny key and value instead of having a string. Simply quoting the thing (or using things like >- etc.) prevents that.

Your explanation makes it so obvious. Thanks!

@felixfontein felixfontein added backport-9 Automatically create a backport for the stable-9 branch and removed breaking_change This PR contains a breaking change that MUST NOT be backported labels Jul 12, 2024
@felixfontein
Copy link
Collaborator

If nobody objects, I'll merge this on Sunday.

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Jul 14, 2024
@felixfontein felixfontein merged commit 21b16c1 into ansible-collections:main Jul 14, 2024
147 checks passed
Copy link

patchback bot commented Jul 14, 2024

Backport to stable-9: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-9/21b16c1c77f732e2c763138ffe03ac80a3897214/pr-8510

Backported as #8621

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Jul 14, 2024
* Update VirtualBox Group parsing to align with documentation.

Previously, we could separate the group string on the `/` char and
consider each element to be distinct, top-level groups. This change
implements the notion of nested groups and the use of the `,` char to
split multiple groups.

* Address code review comments.

Changed the implementation from a breaking change to a minor change by
introducing a new parameter to configure the behaviour. Keep the default
values to maintain the existing behaviour, and allow consumers an option
to opt-in.

* Fix line length.

The long lines were tripping CI. Reduce the length.

* Apply suggestions from code review

Update documentation to match expected conventions and correct the final rendered formatting.
Set the initial parent_group to `None` instead of `all` and rely on the parent class' inventory reconciliation logic to ensure consistent behaviour across different inventory plugins.

Co-authored-by: Felix Fontein <felix@fontein.de>

* Reword module arg description to avoid issues with CI.

One of the lines ended with a colon character which made the CI tests
fail since it would interpret it as a YAML key. Reworded the description
altogether to avoid that issue.

* Apply suggestions from code review

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 21b16c1)
@felixfontein
Copy link
Collaborator

@lyrandy thanks for your contribution!

felixfontein pushed a commit that referenced this pull request Jul 14, 2024
…g to align with documentation. (#8621)

Update VirtualBox Group parsing to align with documentation. (#8510)

* Update VirtualBox Group parsing to align with documentation.

Previously, we could separate the group string on the `/` char and
consider each element to be distinct, top-level groups. This change
implements the notion of nested groups and the use of the `,` char to
split multiple groups.

* Address code review comments.

Changed the implementation from a breaking change to a minor change by
introducing a new parameter to configure the behaviour. Keep the default
values to maintain the existing behaviour, and allow consumers an option
to opt-in.

* Fix line length.

The long lines were tripping CI. Reduce the length.

* Apply suggestions from code review

Update documentation to match expected conventions and correct the final rendered formatting.
Set the initial parent_group to `None` instead of `all` and rely on the parent class' inventory reconciliation logic to ensure consistent behaviour across different inventory plugins.

Co-authored-by: Felix Fontein <felix@fontein.de>

* Reword module arg description to avoid issues with CI.

One of the lines ended with a colon character which made the CI tests
fail since it would interpret it as a YAML key. Reworded the description
altogether to avoid that issue.

* Apply suggestions from code review

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 21b16c1)

Co-authored-by: lyrandy <42095565+lyrandy@users.noreply.github.com>
@lyrandy
Copy link
Contributor Author

lyrandy commented Jul 15, 2024

@lyrandy thanks for your contribution!

Thank you for your guidance and help!

aioue pushed a commit to aioue/community.general that referenced this pull request Oct 1, 2024
…-collections#8510)

* Update VirtualBox Group parsing to align with documentation.

Previously, we could separate the group string on the `/` char and
consider each element to be distinct, top-level groups. This change
implements the notion of nested groups and the use of the `,` char to
split multiple groups.

* Address code review comments.

Changed the implementation from a breaking change to a minor change by
introducing a new parameter to configure the behaviour. Keep the default
values to maintain the existing behaviour, and allow consumers an option
to opt-in.

* Fix line length.

The long lines were tripping CI. Reduce the length.

* Apply suggestions from code review

Update documentation to match expected conventions and correct the final rendered formatting.
Set the initial parent_group to `None` instead of `all` and rely on the parent class' inventory reconciliation logic to ensure consistent behaviour across different inventory plugins.

Co-authored-by: Felix Fontein <felix@fontein.de>

* Reword module arg description to avoid issues with CI.

One of the lines ended with a colon character which made the CI tests
fail since it would interpret it as a YAML key. Reworded the description
altogether to avoid that issue.

* Apply suggestions from code review

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
TobiasZeuch181 pushed a commit to TobiasZeuch181/zypper_repository_add_list that referenced this pull request Oct 2, 2024
…-collections#8510)

* Update VirtualBox Group parsing to align with documentation.

Previously, we could separate the group string on the `/` char and
consider each element to be distinct, top-level groups. This change
implements the notion of nested groups and the use of the `,` char to
split multiple groups.

* Address code review comments.

Changed the implementation from a breaking change to a minor change by
introducing a new parameter to configure the behaviour. Keep the default
values to maintain the existing behaviour, and allow consumers an option
to opt-in.

* Fix line length.

The long lines were tripping CI. Reduce the length.

* Apply suggestions from code review

Update documentation to match expected conventions and correct the final rendered formatting.
Set the initial parent_group to `None` instead of `all` and rely on the parent class' inventory reconciliation logic to ensure consistent behaviour across different inventory plugins.

Co-authored-by: Felix Fontein <felix@fontein.de>

* Reword module arg description to avoid issues with CI.

One of the lines ended with a colon character which made the CI tests
fail since it would interpret it as a YAML key. Reworded the description
altogether to avoid that issue.

* Apply suggestions from code review

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
Massl123 pushed a commit to Massl123/community.general that referenced this pull request Feb 7, 2025
…-collections#8510)

* Update VirtualBox Group parsing to align with documentation.

Previously, we could separate the group string on the `/` char and
consider each element to be distinct, top-level groups. This change
implements the notion of nested groups and the use of the `,` char to
split multiple groups.

* Address code review comments.

Changed the implementation from a breaking change to a minor change by
introducing a new parameter to configure the behaviour. Keep the default
values to maintain the existing behaviour, and allow consumers an option
to opt-in.

* Fix line length.

The long lines were tripping CI. Reduce the length.

* Apply suggestions from code review

Update documentation to match expected conventions and correct the final rendered formatting.
Set the initial parent_group to `None` instead of `all` and rely on the parent class' inventory reconciliation logic to ensure consistent behaviour across different inventory plugins.

Co-authored-by: Felix Fontein <felix@fontein.de>

* Reword module arg description to avoid issues with CI.

One of the lines ended with a colon character which made the CI tests
fail since it would interpret it as a YAML key. Reworded the description
altogether to avoid that issue.

* Apply suggestions from code review

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-9 Automatically create a backport for the stable-9 branch feature This issue/PR relates to a feature request inventory inventory plugin new_contributor Help guide this first time contributor plugins plugin (any type)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Virtualbox Dynamic Inventory Nested Group Assignments
3 participants