1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
---
- name: create default skeleton
command: ansible-galaxy collection init ansible_test.my_collection {{ galaxy_verbosity }}
args:
chdir: '{{ galaxy_dir }}/scratch'
register: init_relative
- name: create required runtime.yml
copy:
content: |
requires_ansible: '>=1.0.0'
dest: '{{ galaxy_dir }}/scratch/ansible_test/my_collection/meta/runtime.yml'
- name: get result of create default skeleton
find:
path: '{{ galaxy_dir }}/scratch/ansible_test/my_collection'
recurse: yes
file_type: directory
register: init_relative_actual
- debug:
var: init_relative_actual.files | map(attribute='path') | list
- name: assert create default skeleton
assert:
that:
- '"Collection ansible_test.my_collection was created successfully" in init_relative.stdout'
- init_relative_actual.files | length == 4
- (init_relative_actual.files | map(attribute='path') | list)[0] | basename in ['docs', 'plugins', 'roles', 'meta']
- (init_relative_actual.files | map(attribute='path') | list)[1] | basename in ['docs', 'plugins', 'roles', 'meta']
- (init_relative_actual.files | map(attribute='path') | list)[2] | basename in ['docs', 'plugins', 'roles', 'meta']
- (init_relative_actual.files | map(attribute='path') | list)[3] | basename in ['docs', 'plugins', 'roles', 'meta']
- name: create collection with custom init path
command: ansible-galaxy collection init ansible_test2.my_collection --init-path "{{ galaxy_dir }}/scratch/custom-init-dir" {{ galaxy_verbosity }}
register: init_custom_path
- name: get result of create default skeleton
find:
path: '{{ galaxy_dir }}/scratch/custom-init-dir/ansible_test2/my_collection'
file_type: directory
register: init_custom_path_actual
- name: assert create collection with custom init path
assert:
that:
- '"Collection ansible_test2.my_collection was created successfully" in init_custom_path.stdout'
- init_custom_path_actual.files | length == 4
- (init_custom_path_actual.files | map(attribute='path') | list)[0] | basename in ['docs', 'plugins', 'roles', 'meta']
- (init_custom_path_actual.files | map(attribute='path') | list)[1] | basename in ['docs', 'plugins', 'roles', 'meta']
- (init_custom_path_actual.files | map(attribute='path') | list)[2] | basename in ['docs', 'plugins', 'roles', 'meta']
- (init_custom_path_actual.files | map(attribute='path') | list)[3] | basename in ['docs', 'plugins', 'roles', 'meta']
- name: add a directory to the init collection path to test that --force removes it
file:
state: directory
path: "{{ galaxy_dir }}/scratch/custom-init-dir/ansible_test2/my_collection/remove_me"
- name: create collection with custom init path
command: ansible-galaxy collection init ansible_test2.my_collection --init-path "{{ galaxy_dir }}/scratch/custom-init-dir" --force {{ galaxy_verbosity }}
register: init_custom_path
- name: get result of create default skeleton
find:
path: '{{ galaxy_dir }}/scratch/custom-init-dir/ansible_test2/my_collection'
file_type: directory
register: init_custom_path_actual
- name: assert create collection with custom init path
assert:
that:
- '"Collection ansible_test2.my_collection was created successfully" in init_custom_path.stdout'
- init_custom_path_actual.files | length == 4
- (init_custom_path_actual.files | map(attribute='path') | list)[0] | basename in ['docs', 'plugins', 'roles', 'meta']
- (init_custom_path_actual.files | map(attribute='path') | list)[1] | basename in ['docs', 'plugins', 'roles', 'meta']
- (init_custom_path_actual.files | map(attribute='path') | list)[2] | basename in ['docs', 'plugins', 'roles', 'meta']
- (init_custom_path_actual.files | map(attribute='path') | list)[3] | basename in ['docs', 'plugins', 'roles', 'meta']
- name: create collection in cwd with custom init path
command: ansible-galaxy collection init ansible_test2.my_collection --init-path ../../ --force {{ galaxy_verbosity }}
args:
chdir: "{{ galaxy_dir }}/scratch/custom-init-dir/ansible_test2/my_collection"
register: init_custom_path
- name: get result of create default skeleton
find:
path: '{{ galaxy_dir }}/scratch/custom-init-dir/ansible_test2/my_collection'
file_type: directory
register: init_custom_path_actual
- name: assert create collection with custom init path
assert:
that:
- '"Collection ansible_test2.my_collection was created successfully" in init_custom_path.stdout'
- init_custom_path_actual.files | length == 4
- (init_custom_path_actual.files | map(attribute='path') | list)[0] | basename in ['docs', 'plugins', 'roles', 'meta']
- (init_custom_path_actual.files | map(attribute='path') | list)[1] | basename in ['docs', 'plugins', 'roles', 'meta']
- (init_custom_path_actual.files | map(attribute='path') | list)[2] | basename in ['docs', 'plugins', 'roles', 'meta']
- (init_custom_path_actual.files | map(attribute='path') | list)[3] | basename in ['docs', 'plugins', 'roles', 'meta']
- name: test using a custom skeleton for collection init
block:
- name: create skeleton directories
file:
path: "{{ galaxy_dir }}/scratch/skeleton/{{ item }}"
state: directory
loop:
- custom_skeleton
- custom_skeleton/plugins
- inventory
- name: create files
file:
path: "{{ galaxy_dir }}/scratch/skeleton/{{ item }}"
state: touch
loop:
- inventory/foo.py
- galaxy.yml
- name: create symlinks
file:
path: "{{ galaxy_dir }}/scratch/skeleton/{{ item.link }}"
src: "{{ galaxy_dir }}/scratch/skeleton/{{ item.source }}"
state: link
loop:
- link: custom_skeleton/plugins/inventory
source: inventory
- link: custom_skeleton/galaxy.yml
source: galaxy.yml
- name: initialize a collection using the skeleton
command: ansible-galaxy collection init ansible_test.my_collection {{ init_path }} {{ skeleton }}
vars:
init_path: '--init-path {{ galaxy_dir }}/scratch/skeleton'
skeleton: '--collection-skeleton {{ galaxy_dir }}/scratch/skeleton/custom_skeleton'
- name: stat expected collection contents
stat:
path: "{{ galaxy_dir }}/scratch/skeleton/ansible_test/my_collection/{{ item }}"
register: stat_result
loop:
- plugins
- plugins/inventory
- galaxy.yml
- plugins/inventory/foo.py
- assert:
that:
- stat_result.results[0].stat.isdir
- stat_result.results[1].stat.islnk
- stat_result.results[2].stat.islnk
- stat_result.results[3].stat.isreg
always:
- name: cleanup
file:
path: "{{ galaxy_dir }}/scratch/skeleton"
state: absent
- name: create collection for ignored files and folders
command: ansible-galaxy collection init ansible_test.ignore
args:
chdir: '{{ galaxy_dir }}/scratch'
- name: create list of ignored files
set_fact:
collection_ignored_files:
- plugins/compiled.pyc
- something.retry
- .git
- name: plant ignored files into the ansible_test.ignore collection
copy:
dest: '{{ galaxy_dir }}/scratch/ansible_test/ignore/{{ item }}'
content: '{{ item }}'
loop: '{{ collection_ignored_files }}'
- name: create list of ignored directories
set_fact:
collection_ignored_directories:
- docs/.git
- plugins/doc_fragments/__pycache__
- .svn
- name: plant ignored folders into the ansible_test.ignore collection
file:
path: '{{ galaxy_dir }}/scratch/ansible_test/ignore/{{ item }}'
state: directory
loop: '{{ collection_ignored_directories }}'
|