You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/test/integration/targets/template/unsafe.yml

65 lines
1.5 KiB
YAML

- hosts: localhost
gather_facts: false
vars:
nottemplated: this should not be seen
imunsafe: !unsafe '{{ nottemplated }}'
tasks:
- set_fact:
this_was_unsafe: >
{{ imunsafe }}
- set_fact:
this_always_safe: '{{ imunsafe }}'
- name: ensure nothing was templated
assert:
that:
- this_always_safe == imunsafe
- imunsafe == this_was_unsafe.strip()
- hosts: localhost
gather_facts: false
vars:
output_dir: "{{ lookup('env', 'OUTPUT_DIR') }}"
tasks:
- set_fact:
unsafe_foo: "{{ lookup('list', var0) }}"
vars:
var0: "{{ var1 }}"
var1:
- unsafe
- assert:
that:
- "{{ unsafe_foo[0] | type_debug == 'AnsibleUnsafeText' }}"
- block:
- copy:
dest: "{{ file_name }}"
content: !unsafe "{{ i_should_not_be_templated }}"
- set_fact:
file_content: "{{ lookup('file', file_name) }}"
- assert:
that:
- not file_content is contains('unsafe')
- set_fact:
file_content: "{{ lookup('file', file_name_tmpl) }}"
vars:
file_name_tmpl: "{{ file_name }}"
- assert:
that:
- not file_content is contains('unsafe')
vars:
file_name: "{{ output_dir }}/unsafe_file"
i_should_not_be_templated: unsafe
always:
- file:
dest: "{{ file_name }}"
state: absent