-
Notifications
You must be signed in to change notification settings - Fork 39
/
cluster.yml
180 lines (175 loc) · 7.56 KB
/
cluster.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
---
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2023 The Nephio Authors.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
- name: Bootstrap Management cluster
hosts: all
vars:
container_engine: docker
clab:
version: 0.42.0
download_url: "https://github.com/srl-labs/containerlab/releases/download"
proxy_env:
http_proxy: "{{ lookup('ansible.builtin.env', 'http_proxy') }}"
https_proxy: "{{ lookup('ansible.builtin.env', 'https_proxy') }}"
no_proxy: "{{ lookup('ansible.builtin.env', 'no_proxy') }}"
HTTP_PROXY: "{{ lookup('ansible.builtin.env', 'HTTP_PROXY') }}"
HTTPS_PROXY: "{{ lookup('ansible.builtin.env', 'HTTPS_PROXY') }}"
NO_PROXY: "{{ lookup('ansible.builtin.env', 'NO_PROXY') }}"
environment: "{{ proxy_env | dict2items | selectattr('value') | items2dict }}"
pre_tasks:
- name: "Print environment variable-based configuration"
become: true
ansible.builtin.debug:
msg:
- "DOCKERHUB_USERNAME: {{ lookup('ansible.builtin.env', 'DOCKERHUB_USERNAME') }}"
- "DOCKERHUB_TOKEN: {{ lookup('ansible.builtin.env', 'DOCKERHUB_TOKEN') }}"
- "DOCKER_REGISTRY_MIRRORS: {{ lookup('ansible.builtin.env', 'DOCKER_REGISTRY_MIRRORS') }}"
- "HTTP_PROXY: {{ lookup('ansible.builtin.env', 'HTTP_PROXY') }}, HTTPS_PROXY: {{ lookup('ansible.builtin.env', 'HTTPS_PROXY') }}"
- "NO_PROXY: {{ lookup('ansible.builtin.env', 'NO_PROXY') }}"
- "http_proxy: {{ lookup('ansible.builtin.env', 'http_proxy') }}, https_proxy: {{ lookup('ansible.builtin.env', 'https_proxy') }}"
- "no_proxy: {{ lookup('ansible.builtin.env', 'no_proxy') }}"
- name: Install kubernetes python package
become: true
ansible.builtin.pip:
name: kubernetes==26.1.0
- name: Install Docker Engine
become: true
when: (container_engine is not defined) or (container_engine == "docker")
block:
- name: Add registry mirrors to docker configuration
ansible.builtin.set_fact:
docker_engine_daemon_json:
registry-mirrors: "{{ lookup('ansible.builtin.env', 'DOCKER_REGISTRY_MIRRORS') }}"
when: lookup('ansible.builtin.env', 'DOCKER_REGISTRY_MIRRORS')
- name: Pass HTTP proxy parameters to the Docker daemon
ansible.builtin.set_fact:
docker_engine_init_exports:
http_proxy: "{{ lookup('ansible.builtin.env', 'http_proxy', default=omit) }}"
HTTP_PROXY: "{{ lookup('ansible.builtin.env', 'HTTP_PROXY', default=omit) }}"
https_proxy: "{{ lookup('ansible.builtin.env', 'https_proxy', default=omit) }}"
HTTPS_PROXY: "{{ lookup('ansible.builtin.env', 'HTTPS_PROXY', default=omit) }}"
no_proxy: "{{ lookup('ansible.builtin.env', 'no_proxy', default=omit) }}"
NO_PROXY: "{{ lookup('ansible.builtin.env', 'NO_PROXY', default=omit) }}"
- name: Install docker binaries
ansible.builtin.include_role:
name: andrewrothstein.docker_engine
- name: Grant Docker permissions to user
ansible.builtin.user:
name: "{{ ansible_user_id }}"
groups: docker
append: true
- name: Install podman binaries
ansible.builtin.include_role:
name: andrewrothstein.podman
when: container_engine == "podman"
- name: Install KinD command-line
ansible.builtin.include_role:
name: andrewrothstein.kind
vars:
kind_config:
sysctl:
fs.inotify.max_user_watches: 524288
fs.inotify.max_user_instances: 512
kernel.keys.maxkeys: 500000
kernel.keys.maxbytes: 1000000
- name: Install kubectl command-line
ansible.builtin.include_role:
name: andrewrothstein.kubectl
- name: Install kpt command-line
ansible.builtin.include_role:
name: andrewrothstein.kpt
vars:
kpt_ver: '1.0.0-beta.49'
kpt_checksums:
'1.0.0-beta.49':
linux_amd64: sha256:8de2996018992ea946c9002aa43c85250a78d9fa3eb1c8da24c7878d7d24b9b7
linux_arm64: sha256:18dfb4540eeed32d2bdded612b3aa678cee6fdcdb14813e184c1a54b4ca35b56
darwin_amd64: sha256:558c1b082a8f1221b88cf6728178076190adda58db84e129ffb40f1e2a462759
darwin_arm64: sha256:bbaa7c6b4c7af0f9cdda694476a9b3b8d9fdd8fba3c0c0ec49f4f26687a2527a
- name: Download CNI plugins
ansible.builtin.include_role:
name: darkwizard242.cni
vars:
ansible_become: true
cni_plugins_dir: /opt/cni/bin
- name: Install container lab tool
become: true
when: ansible_architecture in ('arm64', 'x86_64')
block:
- name: Install container lab on Ubuntu family OS
ansible.builtin.apt:
deb: "{{ clab.download_url }}/v{{ clab.version }}/containerlab_{{ clab.version }}_linux_{{ 'amd64'
if ansible_architecture == 'x86_64' else ansible_architecture }}.deb"
when: ansible_os_family == 'Debian'
- name: Install container lab on RedHat family OS
ansible.builtin.dnf:
name: "{{ clab.download_url }}/v{{ clab.version }}/containerlab_{{ clab.version }}_linux_{{ 'amd64'
if ansible_architecture == 'x86_64' else ansible_architecture }}.rpm"
state: present
disable_gpg_check: true
when: ansible_os_family == 'RedHat'
- name: Configure SELinux for clab
ansible.posix.seboolean:
name: selinuxuser_execmod
state: true
persistent: true
when: ansible_os_family == 'RedHat'
- name: Unarchive /tmp/porchctl.tgz into /usr/local/bin/
become: true
become_user: root
ansible.builtin.unarchive:
remote_src: true
src: https://github.com/nephio-project/porch/releases/download/v2.0.0/porchctl_2.0.0_linux_amd64.tar.gz
dest: /usr/local/bin/
creates: /usr/local/bin/porchctl
roles:
- bootstrap
- install
tasks:
- name: Deploy repositories
ansible.builtin.include_role:
name: kpt
loop:
- {pkg: distros/sandbox/repository, dest: /tmp/repository/mgmt}
- {pkg: nephio/optional/rootsync, dest: /tmp/rootsync/mgmt}
- {pkg: distros/sandbox/repository, dest: /tmp/repository/mgmt-staging}
vars:
repo_uri: "{{ nephio_catalog_repo_uri }}"
local_dest_directory: "{{ item.dest }}"
pkg: "{{ item.pkg }}"
version: main
for_deployment: true
context: "{{ k8s.context }}"
kpt_async: 900
kpt_poll: 0
- name: Wait for packages to be applied
ansible.builtin.async_status:
jid: "{{ item.ansible_job_id }}"
register: job_result
with_items: "{{ all_kpt_apply }}"
when: all_kpt_apply is defined
until: job_result.finished
retries: 90
delay: 10
- name: Wait for repositories
kubernetes.core.k8s:
context: "{{ k8s.context }}"
definition:
apiVersion: config.porch.kpt.dev/v1alpha1
kind: Repository
metadata:
name: "{{ item }}"
namespace: default
wait: true
wait_condition:
type: Ready
status: true
loop:
- mgmt
- mgmt-staging