Skip to content

Commit a6c553e

Browse files
Merge pull request #298 from ErikJiang/enable_repo
Support restore yum repo in enable-repo.yml
2 parents 3c88c08 + f7c0b70 commit a6c553e

File tree

4 files changed

+56
-8
lines changed

4 files changed

+56
-8
lines changed

docs/offline.zh.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ spec:
203203
postHook:
204204
- actionType: playbook
205205
action: cluster-info.yml
206+
- actionType: playbook
207+
action: enable-repo.yml # 在部署集群后, 还原各节点 yum repo 配置. (注:此步骤, 可视情况添加.)
208+
extraArgs: |
209+
-e undo=true
206210
```
207211
208212
## 部署集群前的配置

pkg/util/entrypoint/entrypoint_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ var testData = `
149149
input:
150150
actionType: playbook
151151
action: kubeconfig.yml
152-
extraArgs: "-e postback_undo=true"
153-
matchString: "/kubespray/kubeconfig.yml -e postback_undo=true"
152+
extraArgs: "-e undo=true"
153+
matchString: "/kubespray/kubeconfig.yml -e undo=true"
154154
output: true
155155
156156
- message: "Check entrypoint script cmd concatenation"

playbooks/enable-repo.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
yum_repo_bak_path: /etc/yum.repos.d.bak
99
yum_repo_url_list: []
1010
tasks:
11+
12+
# Install
13+
1114
- name: Checking if "{{ yum_repo_name }}" exists
1215
stat:
1316
path: "{{ yum_repo_src_path }}/{{ yum_repo_name }}.repo"
@@ -22,6 +25,7 @@
2225
when:
2326
- ansible_facts['os_family'] == "RedHat"
2427
- not file_data.stat.exists and ( yum_repo_url_list | length > 0 )
28+
- not undo|default(false)|bool
2529

2630
- name: Enable "{{ yum_repo_name }}" yum repositories
2731
ansible.builtin.yum_repository:
@@ -36,3 +40,43 @@
3640
index_var: url_index
3741
when:
3842
- ansible_facts['os_family'] == "RedHat"
43+
- not undo|default(false)|bool
44+
45+
# Uninstall
46+
47+
- name: Clean extension repo
48+
shell: >
49+
rm -rf {{ yum_repo_src_path }}/{{ yum_repo_name }}.repo
50+
args:
51+
executable: /bin/bash
52+
register: clean_repo_result
53+
until: clean_repo_result.rc == 0
54+
retries: 5
55+
delay: 5
56+
when:
57+
- undo|default(false)|bool
58+
- ansible_facts['os_family'] == "RedHat"
59+
- file_data.stat.exists
60+
61+
- name: Checking if "{{ yum_repo_bak_path }}" exists
62+
stat:
63+
path: "{{ yum_repo_bak_path }}"
64+
register: repo_bak_path
65+
when:
66+
- undo|default(false)|bool
67+
- ansible_facts['os_family'] == "RedHat"
68+
69+
- name: Restore "{{ yum_repo_src_path }}" repo
70+
shell: >
71+
mv {{ yum_repo_bak_path }}/* {{ yum_repo_src_path }}/ &&
72+
rm -rf {{ yum_repo_bak_path }}
73+
args:
74+
executable: /bin/bash
75+
register: restore_repo_result
76+
until: restore_repo_result.rc == 0
77+
retries: 5
78+
delay: 5
79+
when:
80+
- undo|default(false)|bool
81+
- ansible_facts['os_family'] == "RedHat"
82+
- repo_bak_path.stat.exists

playbooks/kubeconfig.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
register: cp_kubeconf_result
1111
until: cp_kubeconf_result is not failed
1212
retries: 10
13-
when: not postback_undo|default(false)|bool
13+
when: not undo|default(false)|bool
1414

1515
- hosts: localhost
1616
gather_facts: false
@@ -29,7 +29,7 @@
2929
executable: /bin/bash
3030
register: update_kubeconfig_result
3131
failed_when: update_kubeconfig_result.stderr
32-
when: not postback_undo|default(false)|bool
32+
when: not undo|default(false)|bool
3333

3434
- name: Check kubeconfig configmap
3535
shell: "kubectl -n kubean-system get configmap {{ kubeconfig_name }}"
@@ -52,7 +52,7 @@
5252
until: create_cm_result.rc == 0
5353
retries: 5
5454
delay: 5
55-
when: not postback_undo|default(false)|bool
55+
when: not undo|default(false)|bool
5656

5757
- name: Patch kubeconfRef info
5858
shell: >
@@ -63,7 +63,7 @@
6363
until: patch_ref_result.rc == 0
6464
retries: 5
6565
delay: 5
66-
when: not postback_undo|default(false)|bool
66+
when: not undo|default(false)|bool
6767

6868
# Uninstall
6969

@@ -76,11 +76,11 @@
7676
until: clean_ref_result.rc == 0
7777
retries: 5
7878
delay: 5
79-
when: postback_undo|default(false)|bool
79+
when: undo|default(false)|bool
8080

8181
- name: Delete local kubeconfig file
8282
shell: "rm -rf {{ local_kube_config }}"
8383
args:
8484
executable: /bin/bash
8585
ignore_errors: true
86-
when: postback_undo|default(false)|bool
86+
when: undo|default(false)|bool

0 commit comments

Comments
 (0)