Skip to content

remove 'allow_duplicates' param for include/import role #82677

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

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from

Conversation

acozine
Copy link
Contributor

@acozine acozine commented Feb 12, 2024

SUMMARY

Part of correcting the documentation about how to deduplicate roles. I've read several issues, many of them closed. I believe that allow_duplicates was never implemented for either include_role or for import_role, and that Ansible currently runs the same role multiple times if a play imports or includes it more than once. This PR removes the parameter from the module documentation for those two modules. A companion PR in ansible-documentation updates the pages on reusing roles to match.

If this isn't correct, I'm happy to change the PR to reflect whatever the current actual behavior of Ansible is.

Related to ansible/ansible-documentation#90.

ISSUE TYPE
  • Docs Pull Request
ADDITIONAL INFORMATION

N/A

@ansibot ansibot added needs_triage Needs a first human triage before being processed. module This issue/PR relates to a module. labels Feb 12, 2024
@flowerysong
Copy link
Contributor

There appears to be some confusion in the original issue between static imports of a role using roles: and the use of import_role. The user's test playbook does not use import_role, so it cannot be used to conclude anything about the behaviour of import_role.

This parameter is and has been implemented for import_role, and it would be inappropriate and confusing to remove the documentation.

It also appears that despite what was stated in replies to the bug, it currently has an effect for include_role:

Test playbook:

- hosts: localhost
  name: import_role with no allowed duplicates
  gather_facts: false
  tasks:
    - import_role:
        name: foo
        allow_duplicates: false

    - import_role:
        name: foo
        allow_duplicates: false

- hosts: localhost
  name: import_role with allowed duplicates
  gather_facts: false
  tasks:
    - import_role:
        name: foo

    - import_role:
        name: foo

- hosts: localhost
  name: include_role with no allowed duplicates
  gather_facts: false
  tasks:
    - include_role:
        name: foo
        allow_duplicates: false

    - include_role:
        name: foo
        allow_duplicates: false

- hosts: localhost
  name: include_role with allowed duplicates
  gather_facts: false
  tasks:
    - include_role:
        name: foo

    - include_role:
        name: foo

Output:

PLAY [import_role with no allowed duplicates] **********************************

TASK [foo : debug] *************************************************************
ok: [localhost] => {
    "msg": "hello from role 'foo'"
}
PLAY [import_role with allowed duplicates] *************************************

TASK [foo : debug] *************************************************************
ok: [localhost] => {
    "msg": "hello from role 'foo'"
}

TASK [foo : debug] *************************************************************
ok: [localhost] => {
    "msg": "hello from role 'foo'"
}
PLAY [include_role with no allowed duplicates] *********************************

TASK [include_role : foo] ******************************************************
included: foo for localhost

TASK [foo : debug] *************************************************************
ok: [localhost] => {
    "msg": "hello from role 'foo'"
}

TASK [include_role : foo] ******************************************************
included: foo for localhost
PLAY [include_role with allowed duplicates] ************************************

TASK [include_role : foo] ******************************************************
included: foo for localhost

TASK [foo : debug] *************************************************************
ok: [localhost] => {
    "msg": "hello from role 'foo'"
}

TASK [include_role : foo] ******************************************************
included: foo for localhost

TASK [foo : debug] *************************************************************
ok: [localhost] => {
    "msg": "hello from role 'foo'"
}

@flowerysong
Copy link
Contributor

flowerysong commented Feb 12, 2024

Oh, and another permutation, which also appears to behave the way the current documentation would suggest:

- hosts: localhost
  name: mixed usage with no allowed duplicates
  gather_facts: false
  tasks:
    - import_role:
        name: foo
        allow_duplicates: false

    - include_role:
        name: foo
        allow_duplicates: false

    - import_role:
        name: foo
        allow_duplicates: false

    - include_role:
        name: foo
        allow_duplicates: false
PLAY [mixed usage with no allowed duplicates] **********************************

TASK [foo : debug] *************************************************************
ok: [localhost] => {
    "msg": "hello from role 'foo'"
}

TASK [include_role : foo] ******************************************************
included: foo for localhost

TASK [include_role : foo] ******************************************************
included: foo for localhost

@s-hertel
Copy link
Contributor

It also appears that despite what was stated in replies to the bug, it currently has an effect for include_role:

I bisected to see when this started, and it looks like a side effect of a templating bug I fixed #80320.

@mkrizek mkrizek removed the needs_triage Needs a first human triage before being processed. label Feb 13, 2024
Copy link
Contributor

@mkrizek mkrizek left a comment

Choose a reason for hiding this comment

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

It appears allow_duplicates works for both include_role and import_role. I suppose we should make sure we have tests for both cases. We should probably also add version_added to the documentation too?

@ansibot ansibot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Feb 13, 2024
@acozine
Copy link
Contributor Author

acozine commented Feb 13, 2024

Oh, excellent - so it's possible to set allow_duplicates: false for both include_role and import_role, and Ansible deduplicates all roles? I can withdraw this PR, or change it to restore the allow_duplicates param and add version_added . . . which would be 2.14? or 2.13?

@s-hertel
Copy link
Contributor

To correct myself, @mkrizek spotted that this has been working since 2.11. The test case I used to bisect was flawed (I set allow_duplicates to the string false by using k=v style arguments, which requires templating to become a boolean). Bisecting again with a boolean leads me to 1b70260.

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Feb 21, 2024
@ansibot ansibot added the stale_pr This PR has not been pushed to for more than one year. label Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. stale_pr This PR has not been pushed to for more than one year.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants