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
120 - name: create symlinks
121 file:
122 path: "{{ galaxy_dir }}/scratch/skeleton/{{ item.link }}"
123 src: "{{ galaxy_dir }}/scratch/skeleton/{{ item.source }}"
124 state: link
125 loop:
126 - link: custom_skeleton/plugins/inventory
127 source: inventory
128 - link: custom_skeleton/galaxy.yml
129 source: galaxy.yml
130
131 - name: create j2 file
132 copy:
133 dest: "{{ galaxy_dir }}/scratch/skeleton/custom_skeleton/README.j2"
134 content: !unsafe |
135 Requires ansible-core >={{ min_ansible_version }}
136
137 - name: initialize a collection using the skeleton
138 command: ansible-galaxy collection init ansible_test.my_collection {{ init_path }} {{ skeleton }} {{ extra }}
139 vars:
140 init_path: '--init-path {{ galaxy_dir }}/scratch/skeleton'
141 skeleton: '--collection-skeleton {{ galaxy_dir }}/scratch/skeleton/custom_skeleton'
142 extra: '-e min_ansible_version="2.17"'
143
144 - name: stat expected collection contents
145 stat:
146 path: "{{ galaxy_dir }}/scratch/skeleton/ansible_test/my_collection/{{ item }}"
147 register: stat_result
148 loop:
149 - plugins
150 - plugins/inventory
151 - galaxy.yml
152 - plugins/inventory/foo.py
153 - README
154
155 - assert:
156 that:
157 - stat_result.results[0].stat.isdir
158 - stat_result.results[1].stat.islnk
159 - stat_result.results[2].stat.islnk
160 - stat_result.results[3].stat.isreg
161 - stat_result.results[4].stat.isreg
162
163 - name: Verify the README was templated successfully
164 copy:
165 dest: "{{ galaxy_dir }}/scratch/skeleton/ansible_test/my_collection/README"
166 content: |
167 Requires ansible-core >=2.17
168 register: validate_readme_content
169
170 - assert:
171 that:
172 - not validate_readme_content.changed
173
174 - name: create a skeleton directory
175 file:
176 path: "{{ galaxy_dir }}/scratch/{{ item }}"
177 state: directory
178 loop:
179 - "invalid_skeleton"
180 - "invalid_skeleton/custom_skeleton"
181
182 - name: create an invalid skeleton ignore expression in ansible.cfg
183 copy:
184 content: |
185 [galaxy]
186 collection_skeleton_ignore=[^.*/.git_keep$
187 dest: "{{ galaxy_dir }}/scratch/invalid_skeleton/ansible.cfg"
188
189 - name: create a collection using the invalid skeleton
190 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
191 register: init_invalid_ignore_expression
192 environment:
193 ANSIBLE_CONFIG: "{{ galaxy_dir }}/scratch/invalid_skeleton/ansible.cfg"
194 ignore_errors: true
195
196 - name: assert create collection with invalid skeleton ignore expression
197 assert:
198 that:
199 - "init_invalid_ignore_expression.failed"
200 - "'Failed to compile regular expressions for skeleton ignore' in init_invalid_ignore_expression.stderr"
201
202 always:
203 - name: cleanup
204 file:
205 path: "{{ galaxy_dir }}/scratch/{{ item }}"
206 state: absent
207 loop:
208 - "skeleton"
209 - "invalid_skeleton"
210
211 - name: create collection for ignored files and folders
212 command: ansible-galaxy collection init ansible_test.ignore
213 args:
214 chdir: '{{ galaxy_dir }}/scratch'
215
216 - name: create list of ignored files
217 set_fact:
218 collection_ignored_files:
219 - plugins/compiled.pyc
220 - something.retry
221 - .git
222
223 - name: plant ignored files into the ansible_test.ignore collection
224 copy:
225 dest: '{{ galaxy_dir }}/scratch/ansible_test/ignore/{{ item }}'
226 content: '{{ item }}'
227 loop: '{{ collection_ignored_files }}'
228
229 - name: create list of ignored directories
230 set_fact:
231 collection_ignored_directories:
232 - docs/.git
233 - plugins/doc_fragments/__pycache__
234 - .svn
235
236 - name: plant ignored folders into the ansible_test.ignore collection
237 file:
238 path: '{{ galaxy_dir }}/scratch/ansible_test/ignore/{{ item }}'
239 state: directory
240 loop: '{{ collection_ignored_directories }}'