Debian Codegraph @

test/integration/targets/ansible-galaxy-collection/tasks/init.yml

raw
1 ---
2 - name: create default skeleton
3 command: ansible-galaxy collection init ansible_test.my_collection {{ galaxy_verbosity }}
4 args:
5 chdir: '{{ galaxy_dir }}/scratch'
6 register: init_relative
7
8 - name: create required runtime.yml
9 copy:
10 content: |
11 requires_ansible: '>=1.0.0'
12 dest: '{{ galaxy_dir }}/scratch/ansible_test/my_collection/meta/runtime.yml'
13
14 - name: get result of create default skeleton
15 find:
16 path: '{{ galaxy_dir }}/scratch/ansible_test/my_collection'
17 recurse: yes
18 file_type: directory
19 register: init_relative_actual
20
21 - debug:
22 var: init_relative_actual.files | map(attribute='path') | list
23
24 - name: assert create default skeleton
25 assert:
26 that:
27 - '"Collection ansible_test.my_collection was created successfully" in init_relative.stdout'
28 - init_relative_actual.files | length == 4
29 - (init_relative_actual.files | map(attribute='path') | list)[0] | basename in ['docs', 'plugins', 'roles', 'meta']
30 - (init_relative_actual.files | map(attribute='path') | list)[1] | basename in ['docs', 'plugins', 'roles', 'meta']
31 - (init_relative_actual.files | map(attribute='path') | list)[2] | basename in ['docs', 'plugins', 'roles', 'meta']
32 - (init_relative_actual.files | map(attribute='path') | list)[3] | basename in ['docs', 'plugins', 'roles', 'meta']
33
34 - name: create collection with custom init path
35 command: ansible-galaxy collection init ansible_test2.my_collection --init-path "{{ galaxy_dir }}/scratch/custom-init-dir" {{ galaxy_verbosity }}
36 register: init_custom_path
37
38 - name: get result of create default skeleton
39 find:
40 path: '{{ galaxy_dir }}/scratch/custom-init-dir/ansible_test2/my_collection'
41 file_type: directory
42 register: init_custom_path_actual
43
44 - name: assert create collection with custom init path
45 assert:
46 that:
47 - '"Collection ansible_test2.my_collection was created successfully" in init_custom_path.stdout'
48 - init_custom_path_actual.files | length == 4
49 - (init_custom_path_actual.files | map(attribute='path') | list)[0] | basename in ['docs', 'plugins', 'roles', 'meta']
50 - (init_custom_path_actual.files | map(attribute='path') | list)[1] | basename in ['docs', 'plugins', 'roles', 'meta']
51 - (init_custom_path_actual.files | map(attribute='path') | list)[2] | basename in ['docs', 'plugins', 'roles', 'meta']
52 - (init_custom_path_actual.files | map(attribute='path') | list)[3] | basename in ['docs', 'plugins', 'roles', 'meta']
53
54 - name: add a directory to the init collection path to test that --force removes it
55 file:
56 state: directory
57 path: "{{ galaxy_dir }}/scratch/custom-init-dir/ansible_test2/my_collection/remove_me"
58
59 - name: create collection with custom init path
60 command: ansible-galaxy collection init ansible_test2.my_collection --init-path "{{ galaxy_dir }}/scratch/custom-init-dir" --force {{ galaxy_verbosity }}
61 register: init_custom_path
62
63 - name: get result of create default skeleton
64 find:
65 path: '{{ galaxy_dir }}/scratch/custom-init-dir/ansible_test2/my_collection'
66 file_type: directory
67 register: init_custom_path_actual
68
69 - name: assert create collection with custom init path
70 assert:
71 that:
72 - '"Collection ansible_test2.my_collection was created successfully" in init_custom_path.stdout'
73 - init_custom_path_actual.files | length == 4
74 - (init_custom_path_actual.files | map(attribute='path') | list)[0] | basename in ['docs', 'plugins', 'roles', 'meta']
75 - (init_custom_path_actual.files | map(attribute='path') | list)[1] | basename in ['docs', 'plugins', 'roles', 'meta']
76 - (init_custom_path_actual.files | map(attribute='path') | list)[2] | basename in ['docs', 'plugins', 'roles', 'meta']
77 - (init_custom_path_actual.files | map(attribute='path') | list)[3] | basename in ['docs', 'plugins', 'roles', 'meta']
78
79 - name: create collection in cwd with custom init path
80 command: ansible-galaxy collection init ansible_test2.my_collection --init-path ../../ --force {{ galaxy_verbosity }}
81 args:
82 chdir: "{{ galaxy_dir }}/scratch/custom-init-dir/ansible_test2/my_collection"
83 register: init_custom_path
84
85 - name: get result of create default skeleton
86 find:
87 path: '{{ galaxy_dir }}/scratch/custom-init-dir/ansible_test2/my_collection'
88 file_type: directory
89 register: init_custom_path_actual
90
91 - name: assert create collection with custom init path
92 assert:
93 that:
94 - '"Collection ansible_test2.my_collection was created successfully" in init_custom_path.stdout'
95 - init_custom_path_actual.files | length == 4
96 - (init_custom_path_actual.files | map(attribute='path') | list)[0] | basename in ['docs', 'plugins', 'roles', 'meta']
97 - (init_custom_path_actual.files | map(attribute='path') | list)[1] | basename in ['docs', 'plugins', 'roles', 'meta']
98 - (init_custom_path_actual.files | map(attribute='path') | list)[2] | basename in ['docs', 'plugins', 'roles', 'meta']
99 - (init_custom_path_actual.files | map(attribute='path') | list)[3] | basename in ['docs', 'plugins', 'roles', 'meta']
100
101 - name: test using a custom skeleton for collection init
102 block:
103 - name: create skeleton directories
104 file:
105 path: "{{ galaxy_dir }}/scratch/skeleton/{{ item }}"
106 state: directory
107 loop:
108 - custom_skeleton
109 - custom_skeleton/plugins
110 - inventory
111
112 - name: create files
113 file:
114 path: "{{ galaxy_dir }}/scratch/skeleton/{{ item }}"
115 state: touch
116 loop:
117 - inventory/foo.py
118 - galaxy.yml
119 - CLAUDE.md
120
121 - name: create a valid skeleton ignore expression in ansible.cfg
122 copy:
123 content: |
124 [galaxy]
125 collection_skeleton_ignore=^\./CLAUDE.md$
126 dest: "{{ galaxy_dir }}/scratch/skeleton/ansible.cfg"
127
128 - name: create symlinks
129 file:
130 path: "{{ galaxy_dir }}/scratch/skeleton/{{ item.link }}"
131 src: "{{ galaxy_dir }}/scratch/skeleton/{{ item.source }}"
132 state: link
133 loop:
134 - link: custom_skeleton/plugins/inventory
135 source: inventory
136 - link: custom_skeleton/galaxy.yml
137 source: galaxy.yml
138
139 - name: create j2 file
140 copy:
141 dest: "{{ galaxy_dir }}/scratch/skeleton/custom_skeleton/README.j2"
142 content: !unsafe |
143 Requires ansible-core >={{ min_ansible_version }}
144
145 - name: initialize a collection using the skeleton
146 command: ansible-galaxy collection init ansible_test.my_collection {{ init_path }} {{ skeleton }} {{ extra }}
147 vars:
148 init_path: '--init-path {{ galaxy_dir }}/scratch/skeleton'
149 skeleton: '--collection-skeleton {{ galaxy_dir }}/scratch/skeleton/custom_skeleton'
150 extra: '-e min_ansible_version="2.17"'
151
152 - name: stat expected collection contents
153 stat:
154 path: "{{ galaxy_dir }}/scratch/skeleton/ansible_test/my_collection/{{ item }}"
155 register: stat_result
156 loop:
157 - plugins
158 - plugins/inventory
159 - galaxy.yml
160 - plugins/inventory/foo.py
161 - README
162 - CLAUDE.md
163
164 - assert:
165 that:
166 - stat_result.results[0].stat.isdir
167 - stat_result.results[1].stat.islnk
168 - stat_result.results[2].stat.islnk
169 - stat_result.results[3].stat.isreg
170 - stat_result.results[4].stat.isreg
171 - not stat_result.results[5].stat.exists
172
173 - name: Verify the README was templated successfully
174 copy:
175 dest: "{{ galaxy_dir }}/scratch/skeleton/ansible_test/my_collection/README"
176 content: |
177 Requires ansible-core >=2.17
178 register: validate_readme_content
179
180 - assert:
181 that:
182 - not validate_readme_content.changed
183
184 - name: create a skeleton directory
185 file:
186 path: "{{ galaxy_dir }}/scratch/{{ item }}"
187 state: directory
188 loop:
189 - "invalid_skeleton"
190 - "invalid_skeleton/custom_skeleton"
191
192 - name: create an invalid skeleton ignore expression in ansible.cfg
193 copy:
194 content: |
195 [galaxy]
196 collection_skeleton_ignore=[^.*/.git_keep$
197 dest: "{{ galaxy_dir }}/scratch/invalid_skeleton/ansible.cfg"
198
199 - name: create a collection using the invalid skeleton
200 command: ansible-galaxy collection init ansible_test.my_collection --init-path {{ galaxy_dir }}/scratch/invalid_skeleton --collection-skeleton {{ galaxy_dir }}/scratch/invalid_skeleton/custom_skeleton
201 register: init_invalid_ignore_expression
202 environment:
203 ANSIBLE_CONFIG: "{{ galaxy_dir }}/scratch/invalid_skeleton/ansible.cfg"
204 ignore_errors: true
205
206 - name: assert create collection with invalid skeleton ignore expression
207 assert:
208 that:
209 - "init_invalid_ignore_expression.failed"
210 - "'Failed to compile regular expressions for skeleton ignore' in init_invalid_ignore_expression.stderr"
211
212 always:
213 - name: cleanup
214 file:
215 path: "{{ galaxy_dir }}/scratch/{{ item }}"
216 state: absent
217 loop:
218 - "skeleton"
219 - "invalid_skeleton"
220
221 - name: create collection for ignored files and folders
222 command: ansible-galaxy collection init ansible_test.ignore
223 args:
224 chdir: '{{ galaxy_dir }}/scratch'
225
226 - name: create list of ignored files
227 set_fact:
228 collection_ignored_files:
229 - plugins/compiled.pyc
230 - something.retry
231 - .git
232
233 - name: plant ignored files into the ansible_test.ignore collection
234 copy:
235 dest: '{{ galaxy_dir }}/scratch/ansible_test/ignore/{{ item }}'
236 content: '{{ item }}'
237 loop: '{{ collection_ignored_files }}'
238
239 - name: create list of ignored directories
240 set_fact:
241 collection_ignored_directories:
242 - docs/.git
243 - plugins/doc_fragments/__pycache__
244 - .svn
245
246 - name: plant ignored folders into the ansible_test.ignore collection
247 file:
248 path: '{{ galaxy_dir }}/scratch/ansible_test/ignore/{{ item }}'
249 state: directory
250 loop: '{{ collection_ignored_directories }}'