forked from redhat-cop/openshift-disconnected-operators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mirror-operator-using-arvin-a-code.yml
executable file
·135 lines (124 loc) · 6.11 KB
/
mirror-operator-using-arvin-a-code.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
#!/usr/local/bin/ansible-playbook --inventory=inventory
- name: 'Mirror Operators for Disconnected OLM | mirror-operator-using-arvin-a-code.yml'
hosts: localhost
become: yes
vars:
ansible_python_interpreter: /usr/bin/python3
vars_files:
- 'vars/vault.yml'
- 'vars/artifactory.yml'
vars:
module: "bundle-operators"
ansible_name_module: "Mirror Operators for Disconnected OLM | {{ module }}"
tasks:
- name: '{{ ansible_name_module }} | podman:login | Login to quay container registry'
no_log: true
command: >
podman login -u {{ default_operator_registry_username }} \
-p {{ default_operator_registry_password }} \
--authfile {{ hostvars[inventory_hostname].ansible_env.HOME }}/.docker/oprconfig.json \
{{ default_operator_registry }}
register: authfile_created
- name: '{{ ansible_name_module }} | podman:login | Login to extra registry'
no_log: true
command: >
podman login -u {{ default_operator_registry_username }} \
-p {{ default_operator_registry_password }} \
--authfile {{ hostvars[inventory_hostname].ansible_env.HOME }}/.docker/oprconfig.json \
{{ item.value.image_registry }}
with_dict:
- "{{ operator_registries_to_mirror }}"
when:
- item.key is defined and item.key != ""
- item.value.mirror is defined and item.value.mirror | bool
- item.value.source is defined and item.value.source != ""
- item.value.image_registry is defined and item.value.image_registry != ""
- name: '{{ ansible_name_module }} | set_fact | authfile for registry'
set_fact:
operator_registry_pull_secret_file: "{{ hostvars[inventory_hostname].ansible_env.HOME }}/.docker/oprconfig.json"
- name: '{{ ansible_name_module }} | podman:run | Start registry container '
command: podman run -d --name {{ registry_container_name }} \
-p 5000:5000 -v {{ registry_container_dir }}:/var/lib/registry:z \
{{ registry_container_image }}
- name: '{{ ansible_name_module }} | copy | copy content template files to staging location '
copy:
src: {{ item }}
dest: "{{ dir_bundle_staging }}/{{ item | basename }}"
force: yes
mode: 0644
with_items:
- known-bad-images
- image-content-source-template
- catalog-source-template
- name: '{{ ansible_name_module }} | shell:echo | create a line separated list of the items to mirror 1 of 2'
shell: echo {{ item.value.mirrored_operator_list }} > {{ dir_bundle_staging }}/{{ item.key }}
with_dict:
- "{{ operator_registries_to_mirror }}"
when:
- item.key is defined and item.key != ""
- item.value.mirror is defined and item.value.mirror | bool
- item.value.source is defined and item.value.source != ""
- item.value.mirrored_operator_list is defined and item.value.mirrored_operator_list != ""
- name: '{{ ansible_name_module }} | shell:sed | create a line separated list of the items to mirror 2 of 2'
shell: sed -i $'s/,/\\\n/g' {{ dir_bundle_staging }}/{{ item.key }}
with_dict:
- "{{ operator_registries_to_mirror }}"
when:
- item.key is defined and item.key != ""
- item.value.mirror is defined and item.value.mirror | bool
- item.value.source is defined and item.value.source != ""
- item.value.mirrored_operator_list is defined and item.value.mirrored_operator_list != ""
- name: '{{ ansible_name_module }} | file:directory | ensure ouput directory exits for each of indices being processed'
file:
path: "{{ dir_bundle_staging }}/{{ item.key }}-publish"
state: directory
mode: 0755
with_dict:
- "{{ operator_registries_to_mirror }}"
when:
- item.key is defined and item.key != ""
- item.value.mirror is defined and item.value.mirror | bool
- item.value.source is defined and item.value.source != ""
- item.value.mirrored_operator_list is defined and item.value.mirrored_operator_list != ""
- name: Mirror operators using Arvin's python script
become: yes
script: >
mirror-operator-catalogue.py --catalog-version=1.0.0 --authfile={{ operator_registry_pull_secret_file }} \
--registry-olm=localhost:5000 --registry-catalog=localhost:5000 --icsp-scope=namespace --run-dir={{ dir_bundle_staging }} \
--operator-image-name={{ item.key }} --operator-catalog-image-url={{ item.value.source.split(':')[0] }} \
--output={{ dir_bundle_staging }}/{{ item.key }}-publish --operator-channel={{ item.value.source.split(':')[1] }} \
--operator-file={{ dir_bundle_staging }}/{{ item.key }}
args:
executable: python3
with_dict:
- "{{ operator_registries_to_mirror }}"
when:
- item.key is defined and item.key != ""
- item.value.mirror is defined and item.value.mirror | bool
- item.value.source is defined and item.value.source != ""
- name: '{{ ansible_name_module }} | block | copy manifest files to container storage location'
when:
- bundle is defined
- bundle | bool
block:
- name: '{{ ansible_name_module }} | command: cp | copy manifest files '
copy:
src: {{ dir_bundle_staging }}/{{ item.key }}-publish
dest: {{ registry_container_dir }}
force: yes
with_dict:
- "{{ operator_registries_to_mirror }}"
when:
- item.key is defined and item.key != ""
- item.value.mirror is defined and item.value.mirror | bool
- item.value.source is defined and item.value.source != ""
- name: '{{ ansible_name_module }} | archive:xz | create operator image bundle '
become: yes
command: >
tar -c --use-compress-program='pigz -9' -v \
-f {{ dir_bundle_location }}/{{ bundle_file_name }} \
-C {{ registry_container_dir }} .
args:
creates: "{{ dir_bundle_location }}/{{ bundle_file_name }}"
warn: false
chdir: "{{ registry_container_dir }}/"