-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsite-remove-submodules.yml
75 lines (65 loc) · 3.12 KB
/
site-remove-submodules.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
################################################################################
# Copyright (c) IBM Corporation 2020
################################################################################
################################################################################
# Description:
# This playbook will remove all the submodules in the superproject. It can be
# altered to pinpoint specific submodules but the purpose this was written for
# was to aid in the testing of the the site-builder.yml playbook such that the
# enviroment is reset.
#
# Remove a submodule process:
# 1) Remove the submodule entry from .git/config
# git submodule deinit -f source/latest || stable/<sub-module>
# 2) Remove the submodule directory from the superproject .git/modules directory
# rm -rf .git/modules/source/latest || stable/<sub-module>
# 3) Remove entry .gitmodules
# git config -f .gitmodules --remove-section submodule.source/<sub-module>
# 4) List all the cached items which include submodules (not a step in remoing submodules)
# git ls-files --stage
# 5) removed the cached submodule
# git rm --cached source/latest || stable/<sub-module>
# 6) remove the submodule repo directories
# rm -rf source/latest || stable/<sub-module>
#
# Usage:
# ansible-playbook -i inventory site-remove-submodules.yaml
################################################################################
---
- hosts: all
gather_facts: no
connection: local
# ##############################################################################
# # Parse 'registry.yml' for certified contributors (key:value)
# ##############################################################################
tasks:
- name: Parse the registry for collection configurations
include_vars: registry.yml
- name: Display the registry details using lookup
debug:
msg: "Collection = {{ item.key }}, git = {{ item.value.git }}, stable = {{ item.value.stable }}, latest = {{ item.value.latest }}"
loop: "{{ lookup('dict', collections) }}"
- name: Display the collection repository names from the registry
debug:
var: collections[item]
with_items: "{{collections}}"
##########################################################################
# Remove all submodules
##########################################################################
# Stat all known collections in this repository after having added unregistered collections
- name: Check if Git submodule exists in the `source/` directory
stat:
path: source/{{ item }}
register: stat_submodule
with_items: "{{collections}}"
- name: Display the submodule stats
debug: msg="{{ stat_submodule }}"
- name: Remove Git submodules
shell: |
git submodule deinit -f source/{{ item.item }}
rm -rf .git/modules/source/{{ item.item }}
git config -f .gitmodules --remove-section submodule.source/{{ item.item }}
git rm --cached source/{{ item.item }}
rm -rf source/{{ item.item }}
with_items: "{{ stat_submodule.results}}"
when: item.stat.exists