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

combine filter: allow merging dict and list #57623

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
3 participants
@tchernomax
Copy link
Contributor

commented Jun 10, 2019

SUMMARY

new feature.

allow the combine filter to merge (append) lists.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

component =lib/ansible/plugins/filter/core.py

ADDITIONAL INFORMATION
- hosts: localhost
  gather_facts: false
  vars:
    toto_default:
      titi:
        titi: truc
      test:
        - a
        - b
    toto:
      titi:
        tata: truc
      test:
        - c
  tasks:
    - debug:
        msg: "{{toto_default|combine(toto, recursive=True)}}"
    - debug:
        msg: "{{toto_default|combine(toto, recursive='merge_hash_and_array')}}"
    - debug:
        msg: "{{toto_default|combine(toto, recursive=False)}}"
max@mde-oxalide % ansible-playbook toto.yml

PLAY [localhost] *************

TASK [debug] *************************
ok: [localhost] => {
    "msg": {
        "test": [
            "c"
        ],
        "titi": {
            "tata": "truc",
            "titi": "truc"
        }
    }
}

TASK [debug] ***********************
ok: [localhost] => {
    "msg": {
        "test": [
            "a",
            "b",
            "c"
        ],
        "titi": {
            "tata": "truc",
            "titi": "truc"
        }
    }
}

TASK [debug] *************************************
ok: [localhost] => {
    "msg": {
        "test": [
            "c"
        ],
        "titi": {
            "tata": "truc"
        }
    }
}

PLAY RECAP *********************
localhost                  : ok=3    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
@ansibot

This comment has been minimized.

Copy link
Contributor

commented Jun 10, 2019

@ansibot

This comment has been minimized.

Copy link
Contributor

commented Jun 10, 2019

The test ansible-test sanity --test compile --python 2.6 [explain] failed with 1 error:

lib/ansible/plugins/filter/core.py:296:29: SyntaxError: def combine(*terms, recursive=None):

The test ansible-test sanity --test compile --python 2.7 [explain] failed with 1 error:

lib/ansible/plugins/filter/core.py:296:29: SyntaxError: def combine(*terms, recursive=None):

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

lib/ansible/plugins/filter/core.py:315:70: E228 missing whitespace around modulo operator
lib/ansible/utils/vars.py:122:1: E302 expected 2 blank lines, found 1

click here for bot help

@ansibot ansibot added needs_revision and removed core_review labels Jun 10, 2019

@tchernomax tchernomax force-pushed the tchernomax:combine_merge_array branch from c3cce39 to 87ae1bf Jun 10, 2019

@ansibot ansibot added core_review and removed needs_revision labels Jun 10, 2019

@tchernomax

This comment has been minimized.

Copy link
Contributor Author

commented Jun 10, 2019

ready_for_review

@tchernomax tchernomax force-pushed the tchernomax:combine_merge_array branch from 87ae1bf to 672b9d7 Jun 11, 2019

@tchernomax tchernomax force-pushed the tchernomax:combine_merge_array branch from 672b9d7 to 179cb8b Jun 11, 2019

@samdoran

This comment has been minimized.

Copy link
Member

commented Jun 11, 2019

We do not want to add this feature as implemented. Please add this to the IRC meeting agenda so we can discuss it further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.