only add data when there is data to add (#54559)
Only add data when there is data to add also avoid clobbering existing data with empty file fixes #45843 * remove redundant code, update comments * fix mock dataloader, original does not return None * added test
This commit is contained in:
4
test/integration/targets/roles/data_integrity.yml
Normal file
4
test/integration/targets/roles/data_integrity.yml
Normal file
@ -0,0 +1,4 @@
|
||||
- hosts: all
|
||||
gather_facts: false
|
||||
roles:
|
||||
- data
|
||||
@ -0,0 +1 @@
|
||||
defined_var: 1
|
||||
5
test/integration/targets/roles/roles/data/tasks/main.yml
Normal file
5
test/integration/targets/roles/roles/data/tasks/main.yml
Normal file
@ -0,0 +1,5 @@
|
||||
- name: ensure data was correctly defind
|
||||
assert:
|
||||
that:
|
||||
- defined_var is defined
|
||||
- defined_var == 1
|
||||
@ -12,3 +12,7 @@ set -eux
|
||||
# include/import can execute another instance of role
|
||||
[ "$(ansible-playbook allowed_dupes.yml -i ../../inventory --tags importrole "$@" | grep -c '"msg": "A"')" = "2" ]
|
||||
[ "$(ansible-playbook allowed_dupes.yml -i ../../inventory --tags includerole "$@" | grep -c '"msg": "A"')" = "2" ]
|
||||
|
||||
|
||||
# ensure role data is merged correctly
|
||||
ansible-playbook data_integrity.yml -i ../../inventory "$@"
|
||||
|
||||
@ -39,10 +39,11 @@ class DictDataLoader(DataLoader):
|
||||
self._vault_secrets = None
|
||||
|
||||
def load_from_file(self, path, cache=True, unsafe=False):
|
||||
data = None
|
||||
path = to_text(path)
|
||||
if path in self._file_mapping:
|
||||
return self.load(self._file_mapping[path], path)
|
||||
return None
|
||||
data = self.load(self._file_mapping[path], path)
|
||||
return data
|
||||
|
||||
# TODO: the real _get_file_contents returns a bytestring, so we actually convert the
|
||||
# unicode/text it's created with to utf-8
|
||||
|
||||
Reference in New Issue
Block a user