Skip to content

[POC] Add projection feature for registering vars - Option 2 #72553

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

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

Conversation

sivel
Copy link
Member

@sivel sivel commented Nov 9, 2020

SUMMARY

This PoC PR updates register to allow authors to pre-process module return results, before registering the variables.

In extension, this allows registering multiple variables

See:

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME
lib/ansible/plugins/strategy/__init__.py
ADDITIONAL INFORMATION
    - command: "echo one"
      register: result

    - debug:
        var: result

    - command: "echo two"
      register:
        result2: ansible_result
        stdout2: ansible_result.stdout
      changed_when: ansible_result.stdout_lines|first == 'not two'

    - debug:
        var: result2

    - debug:
        var: stdout2

    - command: "echo three"
      register:
        stdout3: ansible_result.stdout_lines|first
      changed_when: stdout3 == 'three'

    - command: "echo {{ item }}"
      loop:
        - one
        - two
        - three
      changed_when: ansible_loop_result.stdout_lines|first == 'three'

Either ansible_result must be used in the projection, and represents the task result, all normal jinja follows.

This PR also adds implicit registers named ansible_loop_result and ansible_result. ansible_loop_result will only exist during a looped task, and ansible_result will only exist when not on a looped task. These variables do not persist outside of the TaskExecutor so are only useful for when, changed_when, failed_when, until.

DOCS:

Since docs are no longer maintained in this repo, the docs for this can be located at https://gist.github.com/sivel/376abb3ae5476cfe168361d5ae556f61

TODO:

  • Order of projections can affect later projections
  • Evaluate moving _project off of TE for access in the Strategy also, to deduplicate code
  • Evaluate means of not requiring . as the first character for a projection
  • Evaluate the need for setting register 4 times, which includes running the projections 4 times (3 in TE, 1 in Strategy)

@ansibot ansibot added affects_2.11 core_review In order to be merged, this PR must follow the core review workflow. feature This issue/PR relates to a feature request. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Nov 9, 2020
@sivel sivel marked this pull request as draft November 9, 2020 21:41
@ansibot

This comment has been minimized.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. core_review In order to be merged, this PR must follow the core review workflow. and removed core_review In order to be merged, this PR must follow the core review workflow. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Nov 9, 2020
@Shrews Shrews removed the needs_triage Needs a first human triage before being processed. label Nov 10, 2020
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. core_review In order to be merged, this PR must follow the core review workflow. labels Nov 10, 2020
@ansibot ansibot added stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. has_issue labels Nov 21, 2020
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. pre_azp This PR was last tested before migration to Azure Pipelines. core_review In order to be merged, this PR must follow the core review workflow. and removed core_review In order to be merged, this PR must follow the core review workflow. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. pre_azp This PR was last tested before migration to Azure Pipelines. labels Dec 7, 2020
@nitzmahone nitzmahone changed the title Add projection feature for registering vars - Option 2 [POC] Add projection feature for registering vars - Option 2 Oct 14, 2022
@ansibot ansibot removed 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 Oct 17, 2022
@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 Oct 25, 2022
@sivel
Copy link
Member Author

sivel commented Oct 25, 2022

Added support for using ansible_result in place of .. . still works as a shorthand, but has a limitation of needing to be the first character.

@ansibot ansibot removed 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 Oct 25, 2022
@ansibot
Copy link
Contributor

ansibot commented Oct 26, 2022

The test ansible-test sanity --test docs-build [explain] failed with 1 error:

docs/docsite/rst/playbook_guide/playbooks_variables.rst:242:0: warning: Pygments lexer name 'yaml+jinja2' is not known

click here for bot help

@ansibot ansibot added ci_verified Changes made in this PR are causing tests to fail. and removed ci_verified Changes made in this PR are causing tests to fail. labels Oct 26, 2022
@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 Nov 3, 2022
@ansibot ansibot added the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label Mar 24, 2023
@lachlanmulcahy
Copy link

Is there a chance this will get added to the project? Seems like this has been floating around for a couple of years now.

@sivel
Copy link
Member Author

sivel commented Mar 30, 2023

Yes, there is a chance.

This feature has been included in the experimental fallible (https://pypi.org/project/fallible/) build, and we are waiting on feedback about the feature, to determine if it should be included within ansible-core. See this presentation for more information: https://youtu.be/DCf_e6XRsCw?t=7924

So far, feedback has been limited, and I don't have any specific indication whether anyone has actually tried the feature within the above fallible build or not.

@ansibot ansibot removed needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Mar 30, 2023
@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 Apr 12, 2023
@ansibot ansibot added the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label May 6, 2023
@ansibot ansibot removed the has_issue label Jul 12, 2023
@s-hertel s-hertel mentioned this pull request Oct 10, 2023
1 task
@ansibot ansibot removed needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Oct 12, 2023
@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 Oct 26, 2023
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Jun 12, 2024
@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 Jun 26, 2024
@ansibot ansibot added the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects_2.11 docs This issue/PR relates to or includes documentation. fallible This issue/PR is a candidate for fallible feature This issue/PR relates to a feature request. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html 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. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. WIP This issue/PR is a work in progress. Nevertheless it was shared for getting input from peers.
Projects
Status: TODO: proposed items
Development

Successfully merging this pull request may close these issues.

6 participants