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

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

Draft
wants to merge 27 commits 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: .
        stdout2: ..stdout
        stdout2_r: ansible_result.stdout
      changed_when: ansible_result.stdout_lines|first == 'not two'

    - debug:
        var: result2

    - debug:
        var: stdout2

    - command: "echo three"
      register:
        stdout3: ..stdout_lines|first
        stdout3_r: (ansible_result.stdout_lines)[0]
      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 or a leading . in the projection is required, 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.

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 Nov 9, 2020
@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
@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 Sep 21, 2022
@briantist
Copy link
Contributor

so cool to see work on this again, it's going to be great 🙌

@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 Sep 30, 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 3, 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 11, 2022
@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 the ci_verified Changes made in this PR are causing tests to fail. label Oct 26, 2022
@ansibot ansibot removed the ci_verified Changes made in this PR are causing tests to fail. label 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
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. has_issue 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
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants