Skip to content

Commit 6315e2f

Browse files
CloudyBugwtripp180901sd109
authored
Add a playbook to setup ansible on existing k3s - Standalone mode (#907)
* setup for existing k3s * adds better blocks with conditionals for host setup * updates auth block conditional Co-authored-by: wtripp180901 <[email protected]> * new prometheus override var that fixes CI * defaults to fix ci * added variables to disable prometheus monitoring * one click Azimuth deploy * removed vars overrides * automated groups setup * rename standalone deploy * better groups to work with existing deploy * Groundwork for standalone mode and kubeconfig path rework Co-authored-by: Scott Davidson <[email protected]> * add standalone mode * Improved uri generation --------- Co-authored-by: wtripp180901 <[email protected]> Co-authored-by: Scott Davidson <[email protected]>
1 parent e5dec32 commit 6315e2f

File tree

15 files changed

+204
-52
lines changed

15 files changed

+204
-52
lines changed

playbooks/deploy.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
- role: azimuth_cloud.azimuth_ops.helm_dashboard
2121
- role: azimuth_cloud.azimuth_ops.admin_dashboard_ingress
2222
- role: azimuth_cloud.azimuth_ops.azimuth_authorization_webhook
23-
when: azimuth_authentication_type == "oidc"
23+
when: azimuth_authentication_type == "oidc" and azimuth_cloud_provider_type != "null"
2424
- role: azimuth_cloud.azimuth_ops.harbor
2525
when: harbor_enabled
2626
- role: azimuth_cloud.azimuth_ops.cloud_metrics
@@ -49,7 +49,8 @@
4949
when: azimuth_kubernetes_enabled
5050
- role: azimuth_cloud.azimuth_ops.azimuth_apps_operator
5151
when: azimuth_apps_enabled
52-
- azimuth_cloud.azimuth_ops.azimuth
52+
- role: azimuth_cloud.azimuth_ops.azimuth
53+
5354
# Ensure that Consul is uninstalled
5455
post_tasks:
5556
- name: Ensure Consul is uninstalled

playbooks/deploy_standalone.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#####
2+
# This playbook attempts to setup and install Azimuth on a fresh ubuntu VM
3+
#####
4+
5+
- name: Setup
6+
hosts: azimuth_deploy
7+
tasks:
8+
# HA mode relies on openstack
9+
- name: Fail if install_mode is not standalone
10+
ansible.builtin.fail:
11+
msg: "Install modes other than 'standalone' are not supported for this playbook"
12+
when: install_mode != 'standalone'
13+
14+
- name: Setup host groups
15+
ansible.builtin.add_host:
16+
name: "{{ item }}"
17+
groups:
18+
- k3s
19+
loop: "{{ ansible_play_hosts }}"
20+
21+
# Configure the k3s cluster and add tools
22+
- name: Setup Node
23+
hosts: k3s
24+
tasks:
25+
26+
- name: System setup
27+
become: true
28+
when: configure_system_resources | default (false)
29+
block:
30+
- name: Update packages
31+
ansible.builtin.apt:
32+
update_cache: true
33+
upgrade: true
34+
35+
- name: Configure system trust store
36+
ansible.builtin.include_role:
37+
name: azimuth_cloud.azimuth_ops.system_trust
38+
39+
- name: Set sysctls
40+
ansible.builtin.include_role:
41+
name: azimuth_cloud.azimuth_ops.sysctl_inotify
42+
43+
- name: Install k3s
44+
when: install_k3s
45+
become: true
46+
block:
47+
- name: Install and configure k3s
48+
ansible.builtin.include_role:
49+
name: azimuth_cloud.azimuth_ops.k3s
50+
51+
- name: Install CLI tools
52+
become: true
53+
when: install_cli_tools
54+
block:
55+
- name: Install and configure k9s
56+
ansible.builtin.include_role:
57+
name: azimuth_cloud.azimuth_ops.k9s
58+
59+
- name: Get installed Kubernetes version
60+
ansible.builtin.command: k3s kubectl version --output json
61+
changed_when: false
62+
register: k3s_kubectl_version
63+
64+
- name: Set kubectl version fact
65+
ansible.builtin.set_fact:
66+
kubectl_version: "{{ (k3s_kubectl_version.stdout | from_json).serverVersion.gitVersion.split('+') | first }}"
67+
68+
- name: Install Kubectl
69+
ansible.builtin.include_role:
70+
name: azimuth_cloud.azimuth_ops.kubectl
71+
72+
- name: Install Helm
73+
ansible.builtin.include_role:
74+
name: azimuth_cloud.azimuth_ops.helm
75+
76+
- name: Install Kustomize
77+
ansible.builtin.include_role:
78+
name: azimuth_cloud.azimuth_ops.kustomize
79+
80+
- name: Install Flux
81+
ansible.builtin.include_role:
82+
name: azimuth_cloud.azimuth_ops.flux
83+
tasks_from: cli
84+
when: flux_enabled
85+
86+
- name: Setup Kubeconfig
87+
when: slurp_k3s_kubeconfig
88+
become: true
89+
block:
90+
- name: Slurp kubeconfig file
91+
ansible.builtin.slurp:
92+
src: /etc/rancher/k3s/k3s.yaml
93+
register: k3s_kubeconfig
94+
95+
- name: Ensure kube config directory exists
96+
ansible.builtin.file:
97+
path: "{{ ansible_env.HOME }}/.kube"
98+
state: directory
99+
mode: u=rwx,g=rx,o=rx
100+
101+
- name: Write kubeconfig file
102+
ansible.builtin.copy:
103+
content: "{{ k3s_kubeconfig.content | b64decode }}"
104+
dest: "{{ ansible_env.HOME }}/.kube/config"
105+
mode: u=rwx,g=r,o=r
106+
107+
# For a single node install, we put the monitoring and ingress controller on the K3S cluster
108+
- name: Install monitoring stack and ingress controller
109+
110+
# Configure the K3S cluster as a Cluster API management cluster when doing a HA installation
111+
block:
112+
# Must be done before NGINX ingress so that the ServiceMonitor CRD exists
113+
- name: Install Kube-Prometheus-Stack
114+
ansible.builtin.include_role:
115+
name: azimuth_cloud.azimuth_ops.kube_prometheus_stack
116+
when: deploy_prometheus_stack | default(false)
117+
118+
- name: Install Nginx ingress controller
119+
ansible.builtin.include_role:
120+
name: azimuth_cloud.azimuth_ops.ingress_nginx
121+
when: "ingress_controller_enabled | default(true)"
122+
123+
# Install Azimuth
124+
- name: Install and configure Azimuth
125+
import_playbook: azimuth_cloud.azimuth_ops.deploy

roles/azimuth/defaults/main.yml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@ azimuth_secret_key: "{{ undef(hint='azimuth_secret_key is required') }}"
6161
# Settings for the available clouds
6262
# List of linked clouds - each item should contain name, label and url
6363
azimuth_linked_clouds: []
64-
6564
# The name of this cloud
6665
azimuth_current_cloud_name: "{{ undef(hint='azimuth_current_cloud_name is required') }}"
6766

6867
# The label for this cloud
6968
azimuth_current_cloud_label: >-
7069
{{ azimuth_current_cloud_name | regex_replace('[^a-z0-9]+', ' ') | capitalize }}
7170
71+
# toggle for metrics
72+
azimuth_metrics: true
73+
7274
# Settings for the metrics dashboards, if available
7375
# By default, these are provided by the cloud_metrics role
7476
azimuth_metrics_cloud_metrics_url: >-
@@ -126,14 +128,8 @@ azimuth_oidc_client_spec:
126128
public: false
127129
grantTypes:
128130
- AuthorizationCode
129-
redirectUris:
130-
- >-
131-
{{
132-
"{}://{}/auth/oidc/complete/".format(
133-
'https' if azimuth_ingress_tls_enabled else 'http',
134-
azimuth_ingress_host
135-
)
136-
}}
131+
redirectUris: "{{ ['https://' + azimuth_ingress_host +'/auth/oidc/complete/'] +( ['http://' + azimuth_ingress_host + '/auth/oidc/complete/']
132+
if not azimuth_ingress_tls_enabled else [])}}"
137133
# The client secret
138134
# If not given and an identity realm is being used, a client is created - see above
139135
azimuth_oidc_client_secret: "{{ undef(hint = 'azimuth_oidc_client_secret is required') }}"
@@ -204,7 +200,6 @@ azimuth_authenticator_federated_protocol: >-
204200
else None
205201
}}
206202
azimuth_authenticator_federated_provider:
207-
208203
# The list of identity providers to make available
209204
azimuth_authenticator_federated_identity_providers:
210205
# The Keystone identity provider and protocol to use
@@ -282,7 +277,6 @@ azimuth_authentication_defaults: >-
282277
)
283278
}}
284279
azimuth_authentication_overrides: {}
285-
286280
azimuth_authentication: >-
287281
{{-
288282
azimuth_authentication_defaults |
@@ -300,13 +294,11 @@ azimuth_cloud_provider_type: openstack
300294
# If given, network auto-creation is disabled
301295
# The fragment '{tenant_name}' is replaced with the current tenancy name, e.g. "{tenant_name}-internal"
302296
azimuth_openstack_internal_net_template:
303-
304297
# The template to use when searching for the external network
305298
# Only used if the external network is not tagged
306299
# If not given, there must be exactly one external network available to tenants
307300
# The fragment '{tenant_name}' is replaced with the current tenancy name, e.g. "{tenant_name}-external"
308301
azimuth_openstack_external_net_template:
309-
310302
# If larger than zero, project specific manila share should be auto-created
311303
azimuth_openstack_manila_project_share_gb: 0
312304

@@ -428,10 +420,8 @@ azimuth_scheduling_enabled: false
428420
# Theme settings
429421
# Custom bootstrap CSS URL
430422
azimuth_theme_bootstrap_css_url:
431-
432423
# Custom CSS snippet
433424
azimuth_theme_custom_css:
434-
435425
# The values for the release
436426
azimuth_release_defaults:
437427
tags:
@@ -513,7 +503,7 @@ azimuth_release_defaults:
513503
# Enable the API monitoring by default
514504
api:
515505
monitoring:
516-
enabled: true
506+
enabled: "{{ azimuth_metrics }}"
517507
azimuth_release_overrides: {}
518508
azimuth_release_values: >-
519509
{{-

roles/azimuth_apps_operator/defaults/main.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ azimuth_apps_operator_release_name: azimuth-apps-operator
1313
# The timeout to wait for apps operator to become ready
1414
azimuth_apps_operator_wait_timeout: 10m
1515

16+
# toggle for metrics
17+
azimuth_apps_operator_metrics: true
18+
1619
# Custom trust bundle for SSL verification
1720
azimuth_apps_operator_trust_bundle: "{{ system_trust_ca_bundle | default('') }}"
1821

@@ -93,7 +96,7 @@ azimuth_apps_operator_release_defaults:
9396
}}
9497
# Enable the metrics with the service monitor by default
9598
metrics:
96-
enabled: true
99+
enabled: "{{ azimuth_apps_operator_metrics }}"
97100
trustBundle: "{{ azimuth_apps_operator_trust_bundle }}"
98101
azimuth_apps_operator_release_overrides: {}
99102
azimuth_apps_operator_release_values: >-

roles/azimuth_capi_operator/defaults/main.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ azimuth_capi_operator_trust_bundle: "{{ system_trust_ca_bundle | default('') }}"
1919
# The timer interval to use for the CAPI operator
2020
azimuth_capi_operator_timer_interval: 60
2121

22+
# variable to toggle metrics
23+
azimuth_capi_operator_metrics: true
24+
2225
# The repo, name and version for the CAPI Helm charts
2326
# Leave blank to use the operator defaults
2427
azimuth_capi_operator_capi_helm_chart_repo:
@@ -502,7 +505,7 @@ azimuth_capi_operator_release_defaults:
502505
}}
503506
# Enable the metrics with the service monitor by default
504507
metrics:
505-
enabled: true
508+
enabled: "{{ azimuth_capi_operator_metrics }}"
506509
trustBundle: "{{ azimuth_capi_operator_trust_bundle }}"
507510
azimuth_capi_operator_release_overrides: {}
508511
azimuth_capi_operator_release_values: >-

roles/azimuth_identity_operator/defaults/main.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ azimuth_identity_operator_release_name: azimuth-identity-operator
1313
# The timeout to wait for CAPI operator to become ready
1414
azimuth_identity_operator_wait_timeout: 10m
1515

16+
# toggle for metrics
17+
azimuth_identity_operator_metrics: true
18+
1619
# Custom trust bundle for SSL verification
1720
azimuth_identity_operator_trust_bundle: "{{ system_trust_ca_bundle | default('') }}"
1821

@@ -208,7 +211,7 @@ azimuth_identity_operator_release_defaults:
208211
zenithDiscoveryNamespace: "{{ azimuth_identity_operator_keycloak_zenith_discovery_namespace }}"
209212
# Enable the metrics with the service monitor by default
210213
metrics:
211-
enabled: true
214+
enabled: "{{ azimuth_identity_operator_metrics }}"
212215
trustBundle: "{{ azimuth_identity_operator_trust_bundle }}"
213216
azimuth_identity_operator_release_overrides: {}
214217
azimuth_identity_operator_release_values: >-

roles/ingress_nginx/defaults/main.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ ingress_nginx_release_name: ingress-nginx
1212
# The timeout to wait for NGINX ingress controller to become ready
1313
ingress_nginx_wait_timeout: 10m
1414

15+
# enables the monitoring stack
16+
ingress_nginx_prometheus_stack_enabled: true
17+
1518
# The values for the release
1619
ingress_nginx_release_defaults:
1720
controller:
@@ -24,9 +27,9 @@ ingress_nginx_release_defaults:
2427
config:
2528
annotations-risk-level: Critical
2629
metrics:
27-
enabled: true
30+
enabled: "{{ ingress_nginx_prometheus_stack_enabled }}"
2831
serviceMonitor:
29-
enabled: true
32+
enabled: "{{ ingress_nginx_prometheus_stack_enabled }}"
3033
ingress_nginx_release_overrides: {}
3134
ingress_nginx_release_values: >-
3235
{{-

roles/ingress_nginx/tasks/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@
4747
severity: critical
4848
register: kubectl_ingress_cert_expiry
4949
changed_when: kubectl_ingress_cert_expiry.stdout_lines | select('match', '(?!.*unchanged$)') | length > 0
50+
when: ingress_nginx_prometheus_stack_enabled

roles/k3s/defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ k3s_storage_fstype: xfs
1212

1313
# Indicates if the Traefik ingress controller should be enabled
1414
k3s_traefik_enabled: false
15+
16+
# Variable to disable filesystem setup (for running on existing systems)
17+
k3s_configure_filesystem: true

roles/k3s/tasks/main.yml

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
---
2-
- name: Check if k3s storage device is attached
3-
ansible.builtin.stat:
4-
path: "{{ k3s_storage_device }}"
5-
register: k3s_storage_device_stat
6-
7-
- name: Fail if k3s storage device is missing
8-
ansible.builtin.fail:
9-
msg: "K3s storage device not found at {{ k3s_storage_device }}"
10-
when: not k3s_storage_device_stat.stat.exists
11-
12-
- name: Ensure filesystem exists on storage device
13-
community.general.filesystem:
14-
fstype: "{{ k3s_storage_fstype }}"
15-
dev: "{{ k3s_storage_device }}"
16-
17-
- name: Mount filesystem at required location
18-
ansible.posix.mount:
19-
src: "{{ k3s_storage_device }}"
20-
fstype: "{{ k3s_storage_fstype }}"
21-
path: /var/lib/rancher/k3s
22-
state: mounted
23-
24-
# XFS requires the filesystem to be mounted to do this
25-
- name: Grow filesystem to fill available space
26-
community.general.filesystem:
27-
fstype: "{{ k3s_storage_fstype }}"
28-
dev: "{{ k3s_storage_device }}"
29-
resizefs: true
2+
3+
- name: Configure filesystem
4+
when: k3s_configure_filesystem
5+
block:
6+
- name: Check if k3s storage device is attached
7+
ansible.builtin.stat:
8+
path: "{{ k3s_storage_device }}"
9+
register: k3s_storage_device_stat
10+
11+
- name: Fail if k3s storage device is missing
12+
ansible.builtin.fail:
13+
msg: "K3s storage device not found at {{ k3s_storage_device }}"
14+
when: not k3s_storage_device_stat.stat.exists
15+
16+
- name: Ensure filesystem exists on storage device
17+
community.general.filesystem:
18+
fstype: "{{ k3s_storage_fstype }}"
19+
dev: "{{ k3s_storage_device }}"
20+
21+
- name: Mount filesystem at required location
22+
ansible.posix.mount:
23+
src: "{{ k3s_storage_device }}"
24+
fstype: "{{ k3s_storage_fstype }}"
25+
path: /var/lib/rancher/k3s
26+
state: mounted
27+
28+
# XFS requires the filesystem to be mounted to do this
29+
- name: Grow filesystem to fill available space
30+
community.general.filesystem:
31+
fstype: "{{ k3s_storage_fstype }}"
32+
dev: "{{ k3s_storage_device }}"
33+
resizefs: true
3034

3135
- name: Download k3s binary
3236
ansible.builtin.get_url:

0 commit comments

Comments
 (0)