safe_eval fix (#57188)

* just dont pass locals

 - also fix globals
 - added tests

* fixed tests
This commit is contained in:
Brian Coca
2019-06-06 15:36:22 -04:00
committed by GitHub
parent 99f9f49eca
commit b9b0b23015
10 changed files with 73 additions and 12 deletions

View File

@@ -5,7 +5,7 @@
- name: Registering image name
set_fact:
inames: "{{ inames }} + [iname]"
inames: "{{ inames + [iname]}}"
####################################################################
## build ###########################################################

View File

@@ -35,7 +35,7 @@
register: create_route
- set_fact:
route_ids: "{{ route_ids }} + [ '{{ create_route.data.id }}' ]"
route_ids: "{{ route_ids + [create_route.data.id] }}"
- name: Create second static_route
meraki_static_route:
@@ -50,7 +50,7 @@
register: second_create
- set_fact:
route_ids: "{{ route_ids }} + [ '{{ second_create.data.id }}' ]"
route_ids: "{{ route_ids + [second_create.data.id] }}"
- assert:
that:
@@ -167,4 +167,4 @@
state: absent
org_name: '{{test_org_name}}'
net_name: IntTestNetwork
delegate_to: localhost
delegate_to: localhost

View File

@@ -204,7 +204,7 @@
set_fact:
port_info: []
- set_fact:
port_info: "{{ port_info }} + [{{ item[0] |combine(item[1]) }}]"
port_info: "{{ port_info + [item[0] |combine(item[1])] }}"
loop: "{{ tmp }}"
# Compile list of expected host port information for verifying changes
@@ -225,7 +225,7 @@
set_fact:
expected_port_info: []
- set_fact:
expected_port_info: "{{ expected_port_info }} + [{{ item[0] |combine(item[1]) }}]"
expected_port_info: "{{ expected_port_info + [ item[0] |combine(item[1]) ] }}"
loop: "{{ tmp }}"
# Verify that each host object has the expected protocol type and address/port

View File

@@ -235,7 +235,7 @@
- 'yes'
- set_fact:
encryption_values: '{{ encryption_values }} + ["no"]'
encryption_values: '{{ encryption_values + ["no"]}}'
when: postgres_version_resp.stdout is version('10', '<=')
- include: test_password.yml

View File

@@ -0,0 +1,51 @@
- name: test tempating corner cases
hosts: localhost
gather_facts: false
vars:
empty_list: []
dont: I SHOULD NOT BE TEMPLATED
other: I WORK
tasks:
- name: 'ensure we are not interpolating data from outside of j2 delmiters'
assert:
that:
- '"I SHOULD NOT BE TEMPLATED" not in adjacent'
- globals1 == "[[], globals()]"
- globals2 == "[[], globals]"
vars:
adjacent: "{{ empty_list }} + [dont]"
globals1: "[{{ empty_list }}, globals()]"
globals2: "[{{ empty_list }}, globals]"
- name: 'ensure we can add lists'
assert:
that:
- (empty_list + [other]) == [other]
- (empty_list + [other, other]) == [other, other]
- (dont_exist|default([]) + [other]) == [other]
- ([other] + [empty_list, other]) == [other, [], other]
- name: 'ensure comments go away and we still dont interpolate in string'
assert:
that:
- 'comm1 == " + [dont]"'
- 'comm2 == " #} + [dont]"'
vars:
comm1: '{# {{nothing}} {# #} + [dont]'
comm2: "{# {{nothing}} {# #} #} + [dont]"
- name: test additions with facts, set them up
set_fact:
inames: []
iname: "{{ prefix ~ '-options' }}"
iname_1: "{{ prefix ~ '-options-1' }}"
vars:
prefix: 'bo'
- name: add the facts
set_fact:
inames: '{{ inames + [iname, iname_1] }}'
- assert:
that:
- inames == ['bo-options', 'bo-options-1']

View File

@@ -12,3 +12,7 @@ ansible-playbook ansible_managed.yml -c ansible_managed.cfg -i ../../inventory
# Test for #42585
ANSIBLE_ROLES_PATH=../ ansible-playbook custom_template.yml -i ../../inventory -e @../../integration_config.yml -v "$@"
# Test for several corner cases #57188
ansible-playbook corner_cases.yml -v "$@"