-
Notifications
You must be signed in to change notification settings - Fork 10
/
generate.yml
executable file
·267 lines (232 loc) · 8.06 KB
/
generate.yml
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/usr/bin/env ansible-playbook
---
- name: Generate all files
hosts: localhost
become: no
gather_facts: yes
gather_subset:
- min
vars_files:
- vars/main.yml
tasks:
- name: Set role_path and role_name
ansible.builtin.set_fact:
role_path: "{{ lookup('env', 'PWD') }}"
role_name: "{{ lookup('env', 'PWD') | basename | regex_replace('ansible-role-') }}"
- name: Load generators defaults/main.yml
ansible.builtin.include_vars:
file: defaults/main.yml
- name: Load meta/main.yml
ansible.builtin.include_vars:
file: "{{ role_path }}/meta/main.yml"
name: meta
- name: Check meta/preferences.yml
ansible.builtin.stat:
path: "{{ role_path }}/meta/preferences.yml"
register: preferencesymlstat
- name: Load meta/preferences.yml
ansible.builtin.include_vars:
file: "{{ role_path }}/meta/preferences.yml"
when:
- preferencesymlstat.stat.exists
- name: Check defaults/main.yml
ansible.builtin.stat:
path: "{{ role_path }}/defaults/main.yml"
register: defaultsmainyml
- name: Load defaults/main.yml
ansible.builtin.slurp:
src: "{{ role_path }}/defaults/main.yml"
register: variables
when:
- defaultsmainyml.stat.exists
- name: Check requirements.yml
ansible.builtin.stat:
path: "{{ role_path }}/requirements.yml"
register: check_requirements
- name: Load requirements.yml
ansible.builtin.include_vars:
file: "{{ role_path }}/requirements.yml"
name: requirements
when:
- check_requirements.stat.exists
- name: Load molecule/default/converge.yml
ansible.builtin.slurp:
src: "{{ role_path }}/molecule/default/converge.yml"
register: example
- name: Check molecule/default/prepare.yml
ansible.builtin.stat:
path: "{{ role_path }}/molecule/default/prepare.yml"
register: check_prepare
- name: Load molecule/default/prepare.yml
ansible.builtin.slurp:
src: "{{ role_path }}/molecule/default/prepare.yml"
register: prepare
when:
- check_prepare.stat.exists
- name: Check molecule/default/verify.yml
ansible.builtin.stat:
path: "{{ role_path }}/molecule/default/verify.yml"
register: verify
- name: Load molecule/default/verify.yml
ansible.builtin.slurp:
src: "{{ role_path }}/molecule/default/verify.yml"
register: verifyyml
when:
- verify.stat.exists
- name: Create .github directories
ansible.builtin.file:
path: "{{ role_path }}/{{ item }}"
state: directory
mode: "0755"
loop:
- .github
- .github/workflows
- .github/ISSUE_TEMPLATE
when:
- generate_github_settings or
generate_github_action_molecule or
generate_github_action_galaxy or
generate_github_action_todo or
generate_github_funding or
generate_github_issue_template or
generate_github_feature_template
- name: Copy file
ansible.builtin.copy:
src: "{{ playbook_dir }}/files/{{ item.source }}"
dest: "{{ role_path }}/{{ item.dest | default(item.source) }}"
mode: "{{ item.mode | default('0644') }}"
with_items:
- source: gitignore
dest: .gitignore
- source: yamllint
dest: .yamllint
- source: pre-commit-config.yaml
dest: .pre-commit-config.yaml
- source: pull_request_template.md
dest: .github/pull_request_template.md
- source: requirements.txt
dest: requirements.txt
loop_control:
label: "{{ item.source }}"
- name: Render file README.md
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/README.md.j2"
dest: "{{ role_path }}/README.md"
mode: "0644"
when:
- generate_readme
- name: Render file .ansible-lint
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/ansible-lint.j2"
dest: "{{ role_path }}/.ansible-lint"
mode: "0644"
when:
- generate_ansible_lint
- name: Render file tox.ini
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/tox.ini.j2"
dest: "{{ role_path }}/tox.ini"
mode: "0644"
when:
- generate_tox
# - name: Remove tox.ini
# ansible.builtin.file:
# path: "{{ role_path }}/tox.ini"
# state: absent
- name: Render file .github/settings.yml
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/settings.yml.j2"
dest: "{{ role_path }}/.github/settings.yml"
mode: "0644"
when:
- generate_github_settings
- name: Render file LICENSE
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/LICENSE-2.0.txt.j2"
dest: "{{ role_path }}/LICENSE"
mode: "0644"
when:
- generate_license
- name: Render file SECURITY.md
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/SECURITY.md.j2"
dest: "{{ role_path }}/SECURITY.md"
mode: "0644"
when:
- generate_security
- name: Render file molecule/default/molecule.yml
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/molecule.yml.j2"
dest: "{{ role_path }}/molecule/default/molecule.yml"
mode: "0644"
when:
- generate_molecule
- name: Render file CONTRIBUTING.md
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/CONTRIBUTING.md.j2"
dest: "{{ role_path }}/CONTRIBUTING.md"
mode: "0644"
when:
- generate_contributing
- name: Render file .github/workflows/molecule.yml
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/molecule-action.yml.j2"
dest: "{{ role_path }}/.github/workflows/molecule.yml"
mode: "0644"
when:
- generate_github_action_molecule
- name: Render file .github/workflows/galaxy.yml
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/galaxy.yml.j2"
dest: "{{ role_path }}/.github/workflows/galaxy.yml"
mode: "0644"
when:
- generate_github_action_galaxy
- name: Render file .github/workflows/todo.yml
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/todo-action.yml.j2"
dest: "{{ role_path }}/.github/workflows/todo.yml"
mode: "0644"
when:
- generate_github_action_todo
- name: Render file .gitlab-ci.yml
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/gitlab-ci.yml.j2"
dest: "{{ role_path }}/.gitlab-ci.yml"
mode: "0644"
when:
- generate_gitlab_ci
- name: Render file .github/workflows/requirements2png.yml
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/requirements2png.yml.j2"
dest: "{{ role_path }}/.github/workflows/requirements2png.yml"
mode: "0644"
when:
- generate_requirements2png
- name: Render file .github/FUNDING.yml.md
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/FUNDING.yml.j2"
dest: "{{ role_path }}/.github/FUNDING.yml"
mode: "0644"
when:
- generate_github_funding
- name: Render file github/ISSUE_TEMPLATE/bug_report.md
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/bug_report.md.j2"
dest: "{{ role_path }}/.github/ISSUE_TEMPLATE/bug_report.md"
mode: "0644"
when:
- generate_github_issue_template
- name: Render file .github/ISSUE_TEMPLATE/feature_request.md
ansible.builtin.template:
src: "{{ playbook_dir }}/templates/feature_request.md.j2"
dest: "{{ role_path }}/.github/ISSUE_TEMPLATE/feature_request.md"
mode: "0644"
when:
- generate_github_feature_template
- name: Install pre-commit
ansible.builtin.command:
cmd: pre-commit install
creates: .git/hooks/pre-commit
when:
- generate_pre_commit