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

Sanitize debug var= tasks of the loop variable #66269

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

Conversation

AlanCoding
Copy link
Member

@AlanCoding AlanCoding commented Jan 8, 2020

SUMMARY

Proposed fix for #65856

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

debug

ADDITIONAL INFORMATION

I have a test case for this, modeled after

[ "$(ansible-playbook label.yml "$@" |grep 'item='|sed -e 's/^.*(item=looped_var \(.*\)).*$/\1/')" == "${MATCH}" ]

./runme.sh

(you have to manually inspect the exit code in that case)

inside runme.sh

[ "$(ansible-playbook -i localhost, loop_test.yml | grep 'value2')" == "" ]

inside loop_test.yml

- name: loop_control/debug
  hosts: localhost
  gather_facts: false
  connection: local
  vars:
    my_var: foo
    loop_me:
      - attr1: value1
        attr2: value2
  tasks:

    - name: Echo a var inside of a loop, should only print the label value1
      debug: var=my_var
      loop: "{{ loop_me }}"
      loop_control:
        label: "{{ foo_bar.attr1 }}"
        loop_var: "foo_bar"

    - name: Echo text inside of a loop, should not print anything in loop_me
      debug: msg='hello'
      loop: "{{ loop_me }}"
      loop_control:
        label: "{{ foo_bar.attr1 }}"
        loop_var: "foo_bar"

I am less confident about integrating this into the tests, although there really shouldn't be a problem with it.

and I confirm exit code 1 with devel and exit code 0 with this patch.

@ansibot ansibot added affects_2.10 bug core_review needs_triage small_patch support:core labels Jan 8, 2020
@@ -263,6 +263,10 @@ def _clean_results(self, result, task_name):
# 'var' value as field, so eliminate others and what is left should be varname
for hidme in self._hide_in_debug:
result.pop(hidme, None)
# when using loop control, remove whatever is under loop_var
if 'ansible_loop_var' in result:
Copy link
Contributor

@mkrizek mkrizek Jan 8, 2020

Choose a reason for hiding this comment

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

We might want to do the same for ansible_index_var variable too.

Copy link
Member Author

@AlanCoding AlanCoding Jan 8, 2020

Choose a reason for hiding this comment

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

good call, added that to the test playbook and found it show up. Pushing change now.

Copy link
Member

@bcoca bcoca May 13, 2020

Choose a reason for hiding this comment

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

actually, any var that is not the 'item' in vars= should be removed

@AlanCoding
Copy link
Member Author

AlanCoding commented Jan 8, 2020

I found that this afflicts Ansible 2.9 as well, since it's a bug fix, I'm going to add the changelog

@ansibot ansibot added support:community needs_revision and removed small_patch core_review labels Jan 8, 2020
@mattclay mattclay added the ci_verified label Jan 9, 2020
@bcoca bcoca added the P3 label Jan 14, 2020
@bcoca bcoca self-requested a review Jan 14, 2020
@bcoca bcoca removed the needs_triage label Jan 14, 2020
@ansibot ansibot added the stale_ci label Jan 22, 2020
@ansibot ansibot removed ci_verified stale_ci labels May 6, 2020
@mattclay mattclay added the ci_verified label May 13, 2020
@ansibot ansibot added the stale_ci label May 21, 2020
@ansibot ansibot removed ci_verified needs_revision stale_ci labels Sep 4, 2020
@ansibot ansibot added core_review needs_revision and removed core_review labels Sep 4, 2020
@samdoran samdoran added the ci_verified label Sep 4, 2020
@ansibot ansibot added the stale_ci label Sep 12, 2020
@ansibot ansibot added pre_azp and removed ci_verified stale_ci labels Dec 9, 2020
@ansibot ansibot removed the support:community label Mar 4, 2021
@eqrx eqrx added the ci_verified label Mar 5, 2021
@ansibot ansibot removed the ci_verified label Mar 5, 2021
@samdoran
Copy link
Contributor

samdoran commented Mar 17, 2021

/azp run

@azure-pipelines
Copy link

azure-pipelines bot commented Mar 17, 2021

Azure Pipelines successfully started running 1 pipeline(s).

@ansibot ansibot added core_review needs_revision and removed needs_revision pre_azp core_review labels Mar 17, 2021
@samdoran samdoran added the ci_verified label Mar 19, 2021
@ansibot ansibot added the stale_ci label Mar 27, 2021
@ansibot ansibot added core_review needs_revision and removed ci_verified needs_revision stale_ci core_review labels Apr 19, 2021
@samdoran samdoran added the ci_verified label Apr 21, 2021
@ansibot ansibot added the stale_ci label Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects_2.10 bug ci_verified needs_revision P3 stale_ci support:core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants