diff options
author | Matt Martz <matt@sivel.net> | 2022-09-29 21:45:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-29 21:45:55 +0200 |
commit | c3fc8db41ca0779fd6f724da8b80b8411499906c (patch) | |
tree | c0849184713465ded21a3aa74914c918a800dbc1 | |
parent | Upgrade antsibull-docs to 1.6.1 (#78872) (diff) | |
download | ansible-c3fc8db41ca0779fd6f724da8b80b8411499906c.tar.xz ansible-c3fc8db41ca0779fd6f724da8b80b8411499906c.zip |
Deprecate using a list of dicts for vars. See #78920 (#78927)
10 files changed, 45 insertions, 21 deletions
diff --git a/changelogs/fragments/deprecate-vars-list-of-dicts.yml b/changelogs/fragments/deprecate-vars-list-of-dicts.yml new file mode 100644 index 0000000000..352bf37745 --- /dev/null +++ b/changelogs/fragments/deprecate-vars-list-of-dicts.yml @@ -0,0 +1,2 @@ +deprecated_features: +- vars - Specifying a list of dictionaries for ``vars:`` is deprecated in favor of specifying a dictionary. diff --git a/docs/docsite/rst/porting_guides/porting_guide_core_2.15.rst b/docs/docsite/rst/porting_guides/porting_guide_core_2.15.rst index 12939c7b83..782288c1d1 100644 --- a/docs/docsite/rst/porting_guides/porting_guide_core_2.15.rst +++ b/docs/docsite/rst/porting_guides/porting_guide_core_2.15.rst @@ -31,8 +31,23 @@ No notable changes Deprecated ========== -No notable changes +* Providing a list of dictionaries to ``vars:`` is deprecated in favor of supplying a dictionary. + + Instead of: + + .. code-block:: yaml + + vars: + - var1: foo + - var2: bar + + Use: + + .. code-block:: yaml + vars: + var1: foo + var2: bar Modules ======= diff --git a/lib/ansible/playbook/base.py b/lib/ansible/playbook/base.py index ae7957b0bc..68b98ca184 100644 --- a/lib/ansible/playbook/base.py +++ b/lib/ansible/playbook/base.py @@ -570,6 +570,13 @@ class FieldAttributeBase: _validate_variable_keys(ds) return combine_vars(self.vars, ds) elif isinstance(ds, list): + display.deprecated( + ( + 'Specifying a list of dictionaries for vars is deprecated in favor of ' + 'specifying a dictionary.' + ), + version='2.18' + ) all_vars = self.vars for item in ds: if not isinstance(item, dict): @@ -582,7 +589,7 @@ class FieldAttributeBase: else: raise ValueError except ValueError as e: - raise AnsibleParserError("Vars in a %s must be specified as a dictionary, or a list of dictionaries" % self.__class__.__name__, + raise AnsibleParserError("Vars in a %s must be specified as a dictionary" % self.__class__.__name__, obj=ds, orig_exc=e) except TypeError as e: raise AnsibleParserError("Invalid variable name in vars specified for %s: %s" % (self.__class__.__name__, e), obj=ds, orig_exc=e) diff --git a/test/integration/targets/ansible-vault/test_vault.yml b/test/integration/targets/ansible-vault/test_vault.yml index 7f8ed11570..c21d49a6e0 100644 --- a/test/integration/targets/ansible-vault/test_vault.yml +++ b/test/integration/targets/ansible-vault/test_vault.yml @@ -1,6 +1,6 @@ - hosts: testhost gather_facts: False vars: - - output_dir: . + output_dir: . roles: - { role: test_vault, tags: test_vault} diff --git a/test/integration/targets/ansible-vault/test_vaulted_template.yml b/test/integration/targets/ansible-vault/test_vaulted_template.yml index b495211de8..6a16ec864d 100644 --- a/test/integration/targets/ansible-vault/test_vaulted_template.yml +++ b/test/integration/targets/ansible-vault/test_vaulted_template.yml @@ -1,6 +1,6 @@ - hosts: testhost gather_facts: False vars: - - output_dir: . + output_dir: . roles: - { role: test_vaulted_template, tags: test_vaulted_template} diff --git a/test/integration/targets/blocks/unsafe_failed_task.yml b/test/integration/targets/blocks/unsafe_failed_task.yml index adfa492ad9..e74327b9f8 100644 --- a/test/integration/targets/blocks/unsafe_failed_task.yml +++ b/test/integration/targets/blocks/unsafe_failed_task.yml @@ -1,7 +1,7 @@ - hosts: localhost gather_facts: false vars: - - data: {} + data: {} tasks: - block: - name: template error diff --git a/test/integration/targets/check_mode/check_mode.yml b/test/integration/targets/check_mode/check_mode.yml index a5777506ff..ebf1c5b562 100644 --- a/test/integration/targets/check_mode/check_mode.yml +++ b/test/integration/targets/check_mode/check_mode.yml @@ -1,7 +1,7 @@ - name: Test that check works with check_mode specified in roles hosts: testhost vars: - - output_dir: . + output_dir: . roles: - { role: test_always_run, tags: test_always_run } - { role: test_check_mode, tags: test_check_mode } diff --git a/test/integration/targets/delegate_to/test_delegate_to.yml b/test/integration/targets/delegate_to/test_delegate_to.yml index dcfa9d0351..34cfd20942 100644 --- a/test/integration/targets/delegate_to/test_delegate_to.yml +++ b/test/integration/targets/delegate_to/test_delegate_to.yml @@ -1,9 +1,9 @@ - hosts: testhost3 vars: - - template_role: ./roles/test_template - - output_dir: "{{ playbook_dir }}" - - templated_var: foo - - templated_dict: { 'hello': 'world' } + template_role: ./roles/test_template + output_dir: "{{ playbook_dir }}" + templated_var: foo + templated_dict: { 'hello': 'world' } tasks: - name: Test no delegate_to setup: diff --git a/test/integration/targets/environment/test_environment.yml b/test/integration/targets/environment/test_environment.yml index 43f9c74eb6..f295cf3cab 100644 --- a/test/integration/targets/environment/test_environment.yml +++ b/test/integration/targets/environment/test_environment.yml @@ -7,8 +7,8 @@ - hosts: testhost vars: - - test1: - key1: val1 + test1: + key1: val1 environment: PATH: '{{ansible_env.PATH + ":/lola"}}' lola: 'ido' @@ -41,9 +41,9 @@ - hosts: testhost vars: - - test1: - key1: val1 - - test2: + test1: + key1: val1 + test2: key1: not1 other1: val2 environment: "{{test1}}" diff --git a/test/integration/targets/var_precedence/test_var_precedence.yml b/test/integration/targets/var_precedence/test_var_precedence.yml index 58584bfb3e..b432b2bd6f 100644 --- a/test/integration/targets/var_precedence/test_var_precedence.yml +++ b/test/integration/targets/var_precedence/test_var_precedence.yml @@ -1,12 +1,12 @@ --- - hosts: testhost vars: - - ansible_hostname: "BAD!" - - vars_var: "vars_var" - - param_var: "BAD!" - - vars_files_var: "BAD!" - - extra_var_override_once_removed: "{{ extra_var_override }}" - - from_inventory_once_removed: "{{ inven_var | default('BAD!') }}" + ansible_hostname: "BAD!" + vars_var: "vars_var" + param_var: "BAD!" + vars_files_var: "BAD!" + extra_var_override_once_removed: "{{ extra_var_override }}" + from_inventory_once_removed: "{{ inven_var | default('BAD!') }}" vars_files: - vars/test_var_precedence.yml roles: |