Add conditional to K3s installation;Populate Gitea #2
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Danny Bessems 2022-07-13 12:00:03 +02:00
parent 20ce62fb6d
commit b6ac086a31

View File

@ -1,16 +1,19 @@
- name: Install K3s - block:
- name: Gather service facts
ansible.builtin.service_facts:
# Module requires no attributes
- name: Install K3s
ansible.builtin.command: ansible.builtin.command:
cmd: ./install.sh cmd: ./install.sh
chdir: /opt/metacluster/k3s chdir: /opt/metacluster/k3s
environment: environment:
INSTALL_K3S_SKIP_DOWNLOAD: 'true' INSTALL_K3S_SKIP_DOWNLOAD: 'true'
INSTALL_K3S_EXEC: 'server --cluster-init --disable local-storage' INSTALL_K3S_EXEC: 'server --cluster-init --disable local-storage'
when: ansible_facts.services['k3s.service'] is undefined
- name: Install kubectl tab-completion - name: Ensure API availability
ansible.builtin.shell:
cmd: kubectl completion bash | tee /etc/bash_completion.d/kubectl
- name: Ensure API availability
ansible.utils.cli_parse: ansible.utils.cli_parse:
command: curl -k https://{{ vapp['guestinfo.ipaddress'] }}:6443/livez?verbose command: curl -k https://{{ vapp['guestinfo.ipaddress'] }}:6443/livez?verbose
parser: parser:
@ -21,6 +24,10 @@
retries: 3 retries: 3
delay: 30 delay: 30
- name: Install kubectl tab-completion
ansible.builtin.shell:
cmd: kubectl completion bash | tee /etc/bash_completion.d/kubectl
- block: - block:
- name: Initialize tempfile - name: Initialize tempfile
@ -61,6 +68,7 @@
line: "{{ vapp['guestinfo.ipaddress'] }} {{ item + '.' + vapp['metacluster.fqdn'] }}" line: "{{ vapp['guestinfo.ipaddress'] }} {{ item + '.' + vapp['metacluster.fqdn'] }}"
state: present state: present
loop: loop:
# TODO: Make this list dynamic
- git - git
- gitops - gitops
- registry - registry
@ -113,7 +121,14 @@
dest: /etc/rancher/k3s/registries.yaml dest: /etc/rancher/k3s/registries.yaml
src: registries.j2 src: registries.j2
- name: Install gitea chart - block:
module_defaults:
ansible.builtin.uri:
validate_certs: no
status_code: [200, 201]
body_format: json
- name: Install gitea chart
kubernetes.core.helm: kubernetes.core.helm:
name: gitea name: gitea
chart_ref: /opt/metacluster/helm-charts/gitea chart_ref: /opt/metacluster/helm-charts/gitea
@ -123,8 +138,6 @@
kubeconfig: "{{ kubeconfig.path }}" kubeconfig: "{{ kubeconfig.path }}"
values: "{{ components.gitea.chart_values }}" values: "{{ components.gitea.chart_values }}"
- block:
- name: Ensure gitea API availability - name: Ensure gitea API availability
ansible.utils.cli_parse: ansible.utils.cli_parse:
# Available from Gitea 1.17.x # Available from Gitea 1.17.x
@ -140,7 +153,60 @@
- name: Generate gitea API token - name: Generate gitea API token
ansible.builtin.uri: ansible.builtin.uri:
url: https://git.{{ vapp['metacluster.fqdn']}} url: https://git.{{ vapp['metacluster.fqdn'] }}/api/v1/users/administrator/tokens
method: POST
user: administrator
password: "{{ vapp['guestinfo.rootpw'] }}"
force_basic_auth: yes
body:
name: token_init_{{ lookup('password', '/dev/null length=5 chars=ascii_letters,digits') }}
register: api_token
- name: Create organization(s)
ansible.builtin.uri:
url: https://git.{{ vapp['metacluster.fqdn'] }}/api/v1/orgs
method: POST
headers:
Authorization: token {{ api_token.json.sha1 }}
body: "{{ item }}"
loop:
- full_name: Meta-cluster
description: Meta-cluster configuration items
username: mc
website: https://git.{{ vapp['metacluster.fqdn'] }}/mc
location: '[...]'
visibility: public
- full_name: Workload-cluster
description: Workload-cluster configuration items
username: wl
website: https://git.{{ vapp['metacluster.fqdn'] }}/wl
location: '[...]'
visibility: public
loop_control:
label: "{{ item.full_name }}"
- name: Create repositories
ansible.builtin.uri:
url: https://git.{{ vapp['metacluster.fqdn'] }}/api/v1/orgs/{{ item.organization }}/repos
method: POST
headers:
Authorization: token {{ api_token.json.sha1 }}
body: "{{ item.body }}"
loop:
- organization: mc
body:
name: ArgoCD.Config,
# auto_init: true
default_branch: main
description: GitOps manifests
- organization: wl
body:
name: Template.ArgoCD.Config,
# auto_init: true
default_branch: main
description: GitOps manifests
loop_control:
label: "{{ item.organization + '/' + item.body.name }}"
- name: Install argo-cd chart - name: Install argo-cd chart
kubernetes.core.helm: kubernetes.core.helm: