Debian Codegraph @

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

raw
1 # test code for the assemble module
2 # (c) 2014, James Cammarata <[email protected]>
3
4 # This file is part of Ansible
5 #
6 # Ansible is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Ansible is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
18
19 - name: copy the files to a new directory
20 copy: src="./" dest="{{remote_tmp_dir}}/src"
21 register: result
22
23 - name: create unicode file for test
24 shell: echo "π" > {{ remote_tmp_dir }}/src/ßΩ.txt
25 register: result
26
27 - name: assert that the new file was created
28 assert:
29 that:
30 - "result.changed == true"
31
32 - name: test assemble with all fragments, but only check!
33 assemble: src="{{remote_tmp_dir}}/src" dest="{{remote_tmp_dir}}/assembled1"
34 check_mode: True
35 register: result
36
37 - name: assert the fragments were assembled
38 assert:
39 that:
40 - "result.changed == True"
41
42 - name: ensure file was not created
43 stat:
44 path: "{{remote_tmp_dir}}/assembled1"
45 register: check_it
46
47 - name: it should not exist, yet
48 assert:
49 that:
50 - not check_it.stat.exists
51
52 - name: test assemble with all fragments, really create now!
53 assemble: src="{{remote_tmp_dir}}/src" dest="{{remote_tmp_dir}}/assembled1"
54 register: result2
55
56 - name: assert the fragments were assembled
57 assert:
58 that:
59 - "result2.state == 'file'"
60 - "result2.changed == True"
61 - "result2.checksum == '74152e9224f774191bc0bedf460d35de86ad90e6'"
62
63 - name: ensure file was created
64 stat:
65 path: "{{remote_tmp_dir}}/assembled1"
66 register: check_it2
67
68 - name: it should exist now
69 assert:
70 that:
71 - check_it2.stat.exists
72
73 - name: test assemble with all fragments
74 assemble: src="{{remote_tmp_dir}}/src" dest="{{remote_tmp_dir}}/assembled1"
75 register: result
76
77 - name: assert that the same assemble made no changes
78 assert:
79 that:
80 - "result.state == 'file'"
81 - "result.changed == False"
82 - "result.checksum == '74152e9224f774191bc0bedf460d35de86ad90e6'"
83
84 - name: test assemble with all fragments and decrypt=True
85 assemble: src="{{remote_tmp_dir}}/src" dest="{{remote_tmp_dir}}/assembled2" decrypt=yes
86 register: result
87
88 - name: assert the fragments were assembled with decrypt=True
89 assert:
90 that:
91 - "result.state == 'file'"
92 - "result.changed == True"
93 - "result.checksum == '74152e9224f774191bc0bedf460d35de86ad90e6'"
94
95 - name: test assemble with all fragments and decrypt=True
96 assemble: src="{{remote_tmp_dir}}/src" dest="{{remote_tmp_dir}}/assembled2" decrypt=yes
97 register: result
98
99 - name: assert that the same assemble made no changes with decrypt=True
100 assert:
101 that:
102 - "result.state == 'file'"
103 - "result.changed == False"
104 - "result.checksum == '74152e9224f774191bc0bedf460d35de86ad90e6'"
105
106 - name: test assemble with fragments matching a regex
107 assemble: src="{{remote_tmp_dir}}/src" dest="{{remote_tmp_dir}}/assembled3" regexp="^fragment[1-3]$"
108 register: result
109
110 - name: assert the fragments were assembled with a regex
111 assert:
112 that:
113 - "result.state == 'file'"
114 - "result.checksum == 'edfe2d7487ef8f5ebc0f1c4dc57ba7b70a7b8e2b'"
115
116 - name: test assemble with fragments matching a regex and decrypt=True
117 assemble: src="{{remote_tmp_dir}}/src" dest="{{remote_tmp_dir}}/assembled4" regexp="^fragment[1-3]$" decrypt=yes
118 register: result
119
120 - name: assert the fragments were assembled with a regex and decrypt=True
121 assert:
122 that:
123 - "result.state == 'file'"
124 - "result.checksum == 'edfe2d7487ef8f5ebc0f1c4dc57ba7b70a7b8e2b'"
125
126 - name: test assemble with a delimiter
127 assemble: src="{{remote_tmp_dir}}/src" dest="{{remote_tmp_dir}}/assembled5" delimiter="#--- delimiter ---#"
128 register: result
129
130 - name: assert the fragments were assembled with a delimiter
131 assert:
132 that:
133 - "result.state == 'file'"
134 - "result.checksum == 'd986cefb82e34e4cf14d33a3cda132ff45aa2980'"
135
136 - name: test assemble with a delimiter and decrypt=True
137 assemble: src="{{remote_tmp_dir}}/src" dest="{{remote_tmp_dir}}/assembled6" delimiter="#--- delimiter ---#" decrypt=yes
138 register: result
139
140 - name: assert the fragments were assembled with a delimiter and decrypt=True
141 assert:
142 that:
143 - "result.state == 'file'"
144 - "result.checksum == 'd986cefb82e34e4cf14d33a3cda132ff45aa2980'"
145
146 - name: test assemble with remote_src=False
147 assemble: src="./" dest="{{remote_tmp_dir}}/assembled7" remote_src=no
148 register: result
149
150 - name: assert the fragments were assembled without remote
151 assert:
152 that:
153 - "result.state == 'file'"
154 - "result.checksum == '048a1bd1951aa5ccc427eeb4ca19aee45e9c68b3'"
155
156 - name: test assemble with remote_src=False and decrypt=True
157 assemble: src="./" dest="{{remote_tmp_dir}}/assembled8" remote_src=no decrypt=yes
158 register: result
159
160 - name: assert the fragments were assembled without remote and decrypt=True
161 assert:
162 that:
163 - "result.state == 'file'"
164 - "result.checksum == '048a1bd1951aa5ccc427eeb4ca19aee45e9c68b3'"
165
166 - name: test assemble with remote_src=False and a delimiter
167 assemble: src="./" dest="{{remote_tmp_dir}}/assembled9" remote_src=no delimiter="#--- delimiter ---#"
168 register: result
169
170 - name: assert the fragments were assembled without remote
171 assert:
172 that:
173 - "result.state == 'file'"
174 - "result.checksum == '505359f48c65b3904127cf62b912991d4da7ed6d'"
175
176 - name: test assemble with remote_src=False and a delimiter and decrypt=True
177 assemble: src="./" dest="{{remote_tmp_dir}}/assembled10" remote_src=no delimiter="#--- delimiter ---#" decrypt=yes
178 register: result
179
180 - name: assert the fragments were assembled without remote
181 assert:
182 that:
183 - "result.state == 'file'"
184 - "result.checksum == '505359f48c65b3904127cf62b912991d4da7ed6d'"
185
186 - name: test assemble with diff
187 assemble:
188 src: "./"
189 dest: "{{remote_tmp_dir}}/assembled11"
190 remote_src: false
191 diff: true
192 register: result
193
194 - name: assert the fragments were assembled with diff
195 assert:
196 that:
197 - result.changed
198 - result.diff.after is defined
199 - result.diff.before is defined
200 - "result.state == 'file'"
201
202 - name: Setup for validate test
203 ansible.builtin.file:
204 path: "{{ remote_tmp_dir }}/src_val_syntax"
205 state: directory
206
207 - name: assemble with invalid validation command
208 ansible.builtin.assemble:
209 src: "{{ remote_tmp_dir }}/src_val_syntax"
210 dest: "{{ remote_tmp_dir }}/dest_val_syntax"
211 validate: "echo 'missing %s"
212 register: assemble_syntax_error
213 ignore_errors: yes
214
215 - name: assert assemble failed with ignore_errors
216 assert:
217 that:
218 - assemble_syntax_error.failed
219 - "'Invalid command syntax' in assemble_syntax_error.msg"