Packer.Images/ansible/roles/firstboot/files/ansible_payload/roles/metacluster/tasks/main.yml

165 lines
4.5 KiB
YAML
Raw Normal View History

2022-06-26 16:32:05 +00:00
- name: Install K3s
ansible.builtin.command:
cmd: ./install.sh
chdir: /opt/metacluster/k3s
2022-06-26 16:32:05 +00:00
environment:
INSTALL_K3S_SKIP_DOWNLOAD: 'true'
2022-06-28 10:02:12 +00:00
INSTALL_K3S_EXEC: 'server --cluster-init --disable local-storage'
2022-06-26 16:32:05 +00:00
- name: Install kubectl tab-completion
ansible.builtin.shell:
cmd: kubectl completion bash | tee /etc/bash_completion.d/kubectl
- name: Ensure API availability
ansible.utils.cli_parse:
command: curl -k https://{{ vapp['guestinfo.ipaddress'] }}:6443/livez?verbose
parser:
name: ansible.utils.json
set_fact: api_readycheck
ignore_errors: yes
until: api_readycheck.apiVersion is defined
retries: 3
delay: 30
- block:
- name: Initialize tempfile
ansible.builtin.tempfile:
state: file
register: kubeconfig
- name: Retrieve kubeconfig
ansible.builtin.command:
cmd: kubectl config view --raw
register: kubectl_config
- name: Store kubeconfig in tempfile
ansible.builtin.copy:
dest: "{{ kubeconfig.path }}"
content: "{{ kubectl_config.stdout }}"
mode: 0600
no_log: true
- block:
- name: Extract container images
ansible.builtin.unarchive:
src: /opt/metacluster/container-images/image-tarballs.tgz
dest: /opt/metacluster/container-images
list_files: yes
register: imagetarballs
- name: Import container images
ansible.builtin.command:
cmd: k3s ctr image import {{ item }}
chdir: /opt/metacluster/container-images
loop: "{{ imagetarballs.files }}"
- name: Install longhorn chart
kubernetes.core.helm:
name: longhorn
2022-06-28 09:53:17 +00:00
chart_ref: /opt/metacluster/helm-charts/longhorn
release_namespace: longhorn-system
create_namespace: yes
wait: yes
2022-06-28 09:53:17 +00:00
kubeconfig: "{{ kubeconfig.path }}"
values:
2022-06-28 15:10:24 +00:00
defaultSettings:
defaultDataPath: /mnt/blockstorage
defaultReplicaCount: 1
ingress:
enabled: true
host: storage.{{ vapp['metacluster.fqdn'] }}
persistence:
2022-06-29 15:06:23 +00:00
defaultClassReplicaCount: 1
2022-06-28 09:53:17 +00:00
- name: Install harbor chart
kubernetes.core.helm:
name: harbor
chart_ref: /opt/metacluster/helm-charts/harbor
release_namespace: harbor
create_namespace: yes
wait: yes
2022-06-28 09:53:17 +00:00
kubeconfig: "{{ kubeconfig.path }}"
values:
expose:
ingress:
hosts:
core: registry.{{ vapp['metacluster.fqdn'] }}
externalURL: https://registry.{{ vapp['metacluster.fqdn'] }}
2022-06-30 06:03:13 +00:00
harborAdminPassword: "{{ vapp['guestinfo.rootpw'] }}"
notary:
enabled: false
2022-06-28 09:53:17 +00:00
2022-07-01 08:32:58 +00:00
- name: Push images to registry
ansible.builtin.shell:
2022-07-01 08:39:47 +00:00
cmd: >-
2022-07-01 08:32:58 +00:00
skopeo copy \
--dest-tls-verify=false \
--dest-creds admin:{{ vapp['guestinfo.rootpw'] }} \
docker-archive:./{{ item }} \
docker://registry.{{ vapp['metacluster.fqdn'] }}/library/$( \
2022-07-01 08:32:58 +00:00
k3s ctr run \
--rm \
--mount type=bind,src=$PWD,dst=/data,options=rbind:ro \
2022-07-01 11:10:26 +00:00
quay.io/skopeo/stable:v1.8.0 skopeo \
skopeo list-tags docker-archive:/data/{{ item }} | \
2022-07-01 08:32:58 +00:00
jq -r '.Tags[0]')
chdir: /opt/metacluster/container-images/
loop: "{{ imagetarballs.files }}"
2022-07-01 11:10:26 +00:00
- name: Delete container image tarballs/archives
ansible.builtin.file:
path: /opt/metacluster/container-images
state: absent
2022-07-01 08:32:58 +00:00
- name: Configure K3s node for private registry
ansible.builtin.template:
dest: /etc/rancher/k3s/registries.yaml
src: registries.j2
2022-07-03 13:19:41 +00:00
2022-07-03 13:08:57 +00:00
- name: Install gitea chart
kubernetes.core.helm:
name: gitea
chart_ref: /opt/metacluster/helm-charts/gitea
release_namespace: gitea
create_namespace: yes
wait: yes
kubeconfig: "{{ kubeconfig.path }}"
values:
gitea:
admin:
username: administrator
2022-07-03 13:08:57 +00:00
password: "{{ vapp['guestinfo.rootpw'] }}"
email: admin@{{ vapp['metacluster.fqdn'] }}
image:
pullPolicy: IfNotPresent
ingress:
2022-07-04 13:21:47 +00:00
enabled: true
2022-07-03 13:08:57 +00:00
hosts:
- host: git.{{ vapp['metacluster.fqdn'] }}
paths:
- path: /
pathType: Prefix
2022-07-05 07:56:56 +00:00
- name: Install argo-cd chart
kubernetes.core.helm:
name: argo-cd
chart_ref: /opt/metacluster/helm-charts/argo-cd
release_namespace: argo-cd
create_namespace: yes
wait: yes
kubeconfig: "{{ kubeconfig.path }}"
values:
server:
ingress:
enabled: true
hosts:
- gitops.{{ vapp['metacluster.fqdn'] }}
- name: Cleanup tempfile
ansible.builtin.file:
path: "{{ kubeconfig.path }}"
state: absent
when: kubeconfig.path is defined