From f6866e1a11198b7254dc5ddc535e838e41c952b2 Mon Sep 17 00:00:00 2001 From: Rafael Bradley Date: Fri, 15 Aug 2025 21:06:56 -0300 Subject: [PATCH] Set up ansible scripts to install k3s, helm, and ArgoCD in a Debian-based node --- .ansible/.lock | 0 .gitignore | 3 +++ .python-version | 1 + .vscode/settings.json | 3 ++- inventory.ini | 2 ++ playbooks/dev/01-setup.yml | 42 +++++++++++++++++++++++++++++++++++++ playbooks/dev/02-argocd.yml | 30 ++++++++++++++++++++++++++ pyproject.toml | 10 +++++++++ 8 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 .ansible/.lock create mode 100644 .python-version create mode 100644 inventory.ini create mode 100644 playbooks/dev/01-setup.yml create mode 100644 playbooks/dev/02-argocd.yml create mode 100644 pyproject.toml diff --git a/.ansible/.lock b/.ansible/.lock new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore index 83a00ee..d5bfb48 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ /target +/.venv .env + +uv.lock \ No newline at end of file diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..e4fba21 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.12 diff --git a/.vscode/settings.json b/.vscode/settings.json index f89ed5f..f9e88ec 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "editor.formatOnSave": true + "editor.formatOnSave": true, + "ansible.python.interpreterPath": "/home/nyeki/Documents/Repositories/payphone/payphone/.venv/bin/python" } diff --git a/inventory.ini b/inventory.ini new file mode 100644 index 0000000..546e7ce --- /dev/null +++ b/inventory.ini @@ -0,0 +1,2 @@ +[dev] +dev-node ansible_host=p4.vps.nyeki.dev ansible_user=root \ No newline at end of file diff --git a/playbooks/dev/01-setup.yml b/playbooks/dev/01-setup.yml new file mode 100644 index 0000000..469e3bb --- /dev/null +++ b/playbooks/dev/01-setup.yml @@ -0,0 +1,42 @@ +- name: Set up k3s on dev node + hosts: dev + become: true + tasks: + - name: Install curl + ansible.builtin.apt: + name: curl + state: present + when: ansible_os_family == "Debian" + + - name: Download k3s install script + ansible.builtin.get_url: + url: https://get.k3s.io + dest: /tmp/k3s_install.sh + mode: '0755' + + - name: Run k3s installer + ansible.builtin.command: /tmp/k3s_install.sh + args: + creates: /usr/local/bin/k3s + + - name: Ensure k3s service is started and enabled + ansible.builtin.systemd: + name: k3s + enabled: true + state: started + + - name: Install Python Kubernetes client + ansible.builtin.apt: + name: python3-kubernetes + state: present + + - name: Download helm install script + ansible.builtin.get_url: + url: https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 + dest: /tmp/get_helm.sh + mode: '0755' + + - name: Run helm installer + ansible.builtin.command: /tmp/get_helm.sh + args: + creates: /usr/local/bin/helm diff --git a/playbooks/dev/02-argocd.yml b/playbooks/dev/02-argocd.yml new file mode 100644 index 0000000..5d774f0 --- /dev/null +++ b/playbooks/dev/02-argocd.yml @@ -0,0 +1,30 @@ +- name: Set up ArgoCD + hosts: dev + become: true + tasks: + - name: Create ArgoCD namespace + kubernetes.core.k8s: + api_version: v1 + kind: Namespace + name: argocd + kubeconfig: /etc/rancher/k3s/k3s.yaml + + - name: Apply ArgoCD installation manifest + kubernetes.core.k8s: + state: present + src: https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml + namespace: argocd + kubeconfig: /etc/rancher/k3s/k3s.yaml + + - name: Get ArgoCD initial admin password + ansible.builtin.shell: kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" + register: encoded_pass + changed_when: false + + - name: Decode ArgoCD password + ansible.builtin.set_fact: + argocd_pass: "{{ encoded_pass.stdout | b64decode }}" + + - name: Show ArgoCD password + ansible.builtin.debug: + msg: "ArgoCD admin password: {{ argocd_pass }}" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..43b4d48 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,10 @@ +[project] +name = "payphone" +version = "0.1.0" +description = "Add your description here" +readme = "README.md" +requires-python = ">=3.12" +dependencies = [ + "ansible>=11.9.0", + "ansible-lint>=25.8.1", +]