Debian Codegraph @

test/integration/targets/slurp/tasks/main.yml

raw
1 # Copyright: (c) 2025, Ansible Project
2 # (c) 2014, Chris Church <[email protected]>
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5 # test code for the slurp module. Based on win_slurp test cases
6 - name: Create a UTF-8 file to test with
7 copy:
8 content: 'We are at the café'
9 dest: '{{ remote_tmp_dir }}/foo.txt'
10
11 - name: test slurping an existing file
12 slurp:
13 src: '{{ remote_tmp_dir }}/foo.txt'
14 register: slurp_existing
15
16 - name: check slurp existing result
17 assert:
18 that:
19 - slurp_existing.content is truthy
20 - slurp_existing.encoding == "base64"
21 - slurp_existing is not changed
22 - slurp_existing is not failed
23 - slurp_existing.content | b64decode == "We are at the café"
24
25 - name: test slurping w/o encoding
26 slurp:
27 src: '{{ remote_tmp_dir }}/foo.txt'
28 armor: off
29 register: slurp_existing_noarmor
30
31 - name: check slurp existing result no armor
32 assert:
33 that:
34 - slurp_existing_noarmor.content is truthy
35 - slurp_existing_noarmor.encoding == "utf-8"
36 - slurp_existing_noarmor is not changed
37 - slurp_existing_noarmor is not failed
38 - slurp_existing_noarmor.content == "We are at the café"
39
40 - name: Create a binary file to test with
41 copy:
42 src: bar.bin
43 dest: '{{ remote_tmp_dir }}/bar.bin'
44
45 - name: test slurping a binary file
46 slurp:
47 path: '{{ remote_tmp_dir }}/bar.bin'
48 register: slurp_binary
49 no_log: true
50
51 - name: check slurp result of binary
52 assert:
53 that:
54 - slurp_binary.content is truthy
55 - slurp_binary.encoding == 'base64'
56 - slurp_binary is not changed
57 - slurp_binary is not failed
58
59 - name: test slurp with missing argument
60 action: slurp
61 register: slurp_no_args
62 ignore_errors: true
63
64 - name: check slurp with missing argument result
65 assert:
66 that:
67 - slurp_no_args is failed
68 - slurp_no_args.msg is truthy
69 - slurp_no_args is not changed
70
71 - import_tasks: test_unreadable.yml