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

Add a dynamic version of blocks. #72397

Open
wants to merge 4 commits into
base: devel
Choose a base branch
from

Conversation

estheruary
Copy link
Contributor

@estheruary estheruary commented Oct 29, 2020

SUMMARY

Adds a new keyword/module called do which is the dynamic version of block. Among other things, this allows you to loop over multiple tasks without including an external file.

We have include as the dynamic version of import. How about do as the dynamic version of block?

## Replaces this:
# 

- name: Loop over tasks.
  include_tasks: stuff.yml
  loop: "{{ items }}"

# stuff.yml
- name: Task 1
  debug:
    msg: Task 1

- name: Task 2
  debug:
    var: item
## With this
#

- name: Loop over tasks.
  do:
    - name: Task 1
      debug:
        msg: Task 1

    - name: Task 2
      debug:
        var: item
  loop: "{{ items }}"
ISSUE TYPE
  • Feature Pull Request

Spiritually implements #13262

COMPONENT NAME

do

ADDITIONAL INFORMATION

Right now the feature works but obviously needs some testing and documentation. Figured I'd hold off on the tedious parts until I find out if this is something you folks actually want upstream.

The name is inspired by how Ruby handles passing blocks.

@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. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_module This PR includes a new module. new_plugin This PR includes a new plugin. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Oct 29, 2020
@bcoca bcoca removed the needs_triage Needs a first human triage before being processed. label Oct 29, 2020
@ansibot
Copy link
Contributor

ansibot commented Oct 29, 2020

The test ansible-test sanity --test validate-modules [explain] failed with 1 error:

lib/ansible/modules/do.py:0:0: invalid-documentation: DOCUMENTATION.author: Invalid author for dictionary value @ data['author']. Got 'Estelle Poulin (dev@inspiredby.es)'

The test ansible-test sanity --test pylint [explain] failed with 4 errors:

lib/ansible/parsing/mod_args.py:219:19: bad-whitespace: No space allowed after bracket             args = { u'_raw_params': thing }                    ^
lib/ansible/parsing/mod_args.py:219:43: bad-whitespace: No space allowed before bracket             args = { u'_raw_params': thing }                                            ^
lib/ansible/playbook/task_include.py:120:48: bad-whitespace: No space allowed before :         if self.action not in ('include', 'do') :                                                 ^
lib/ansible/plugins/strategy/free.py:308:0: trailing-whitespace: Trailing whitespace

The test ansible-test sanity --test pep8 [explain] failed with 5 errors:

lib/ansible/parsing/mod_args.py:219:21: E201: whitespace after '{'
lib/ansible/parsing/mod_args.py:219:43: E202: whitespace before '}'
lib/ansible/playbook/task_include.py:120:48: E203: whitespace before ':'
lib/ansible/plugins/strategy/free.py:308:1: W293: blank line contains whitespace
lib/ansible/plugins/strategy/free.py:310:13: E303: too many blank lines (2)

click here for bot help

@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 Oct 29, 2020
@ansibot
Copy link
Contributor

ansibot commented Nov 4, 2020

@estheruary this PR contains the following merge commits:

Please rebase your branch to remove these commits.

click here for bot help

@ansibot ansibot added merge_commit This PR contains at least one merge commit. Please resolve! 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. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Nov 4, 2020
@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 12, 2020
@ansibot ansibot added pre_azp This PR was last tested before migration to Azure Pipelines. 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 Dec 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects_2.11 feature This issue/PR relates to a feature request. merge_commit This PR contains at least one merge commit. Please resolve! module This issue/PR relates to a module. 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. new_module This PR includes a new module. new_plugin This PR includes a new plugin. pre_azp This PR was last tested before migration to Azure Pipelines. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants