Deprecate using a list of dicts for vars. See #78920 (#78927)

pull/78934/head
Matt Martz 2 years ago committed by GitHub
parent d93883645c
commit c3fc8db41c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
deprecated_features:
- vars - Specifying a list of dictionaries for ``vars:`` is deprecated in favor of specifying a dictionary.

@ -31,8 +31,23 @@ No notable changes
Deprecated 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 Modules
======= =======

@ -570,6 +570,13 @@ class FieldAttributeBase:
_validate_variable_keys(ds) _validate_variable_keys(ds)
return combine_vars(self.vars, ds) return combine_vars(self.vars, ds)
elif isinstance(ds, list): 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 all_vars = self.vars
for item in ds: for item in ds:
if not isinstance(item, dict): if not isinstance(item, dict):
@ -582,7 +589,7 @@ class FieldAttributeBase:
else: else:
raise ValueError raise ValueError
except ValueError as e: 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) obj=ds, orig_exc=e)
except TypeError as 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) raise AnsibleParserError("Invalid variable name in vars specified for %s: %s" % (self.__class__.__name__, e), obj=ds, orig_exc=e)

@ -1,6 +1,6 @@
- hosts: testhost - hosts: testhost
gather_facts: False gather_facts: False
vars: vars:
- output_dir: . output_dir: .
roles: roles:
- { role: test_vault, tags: test_vault} - { role: test_vault, tags: test_vault}

@ -1,6 +1,6 @@
- hosts: testhost - hosts: testhost
gather_facts: False gather_facts: False
vars: vars:
- output_dir: . output_dir: .
roles: roles:
- { role: test_vaulted_template, tags: test_vaulted_template} - { role: test_vaulted_template, tags: test_vaulted_template}

@ -1,7 +1,7 @@
- hosts: localhost - hosts: localhost
gather_facts: false gather_facts: false
vars: vars:
- data: {} data: {}
tasks: tasks:
- block: - block:
- name: template error - name: template error

@ -1,7 +1,7 @@
- name: Test that check works with check_mode specified in roles - name: Test that check works with check_mode specified in roles
hosts: testhost hosts: testhost
vars: vars:
- output_dir: . output_dir: .
roles: roles:
- { role: test_always_run, tags: test_always_run } - { role: test_always_run, tags: test_always_run }
- { role: test_check_mode, tags: test_check_mode } - { role: test_check_mode, tags: test_check_mode }

@ -1,9 +1,9 @@
- hosts: testhost3 - hosts: testhost3
vars: vars:
- template_role: ./roles/test_template template_role: ./roles/test_template
- output_dir: "{{ playbook_dir }}" output_dir: "{{ playbook_dir }}"
- templated_var: foo templated_var: foo
- templated_dict: { 'hello': 'world' } templated_dict: { 'hello': 'world' }
tasks: tasks:
- name: Test no delegate_to - name: Test no delegate_to
setup: setup:

@ -7,7 +7,7 @@
- hosts: testhost - hosts: testhost
vars: vars:
- test1: test1:
key1: val1 key1: val1
environment: environment:
PATH: '{{ansible_env.PATH + ":/lola"}}' PATH: '{{ansible_env.PATH + ":/lola"}}'
@ -41,9 +41,9 @@
- hosts: testhost - hosts: testhost
vars: vars:
- test1: test1:
key1: val1 key1: val1
- test2: test2:
key1: not1 key1: not1
other1: val2 other1: val2
environment: "{{test1}}" environment: "{{test1}}"

@ -1,12 +1,12 @@
--- ---
- hosts: testhost - hosts: testhost
vars: vars:
- ansible_hostname: "BAD!" ansible_hostname: "BAD!"
- vars_var: "vars_var" vars_var: "vars_var"
- param_var: "BAD!" param_var: "BAD!"
- vars_files_var: "BAD!" vars_files_var: "BAD!"
- extra_var_override_once_removed: "{{ extra_var_override }}" extra_var_override_once_removed: "{{ extra_var_override }}"
- from_inventory_once_removed: "{{ inven_var | default('BAD!') }}" from_inventory_once_removed: "{{ inven_var | default('BAD!') }}"
vars_files: vars_files:
- vars/test_var_precedence.yml - vars/test_var_precedence.yml
roles: roles:

Loading…
Cancel
Save