From f94912c43b787305b95c4e6771bea4bd494c6964 Mon Sep 17 00:00:00 2001 From: NoSpawnn Date: Fri, 30 May 2025 15:51:00 +0100 Subject: [PATCH 1/6] Test webserver in playbook (THIS IS HACKY) --- .../deploy/ansible/playbook.yml | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml b/repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml index bb2b500..ad18cf5 100644 --- a/repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml +++ b/repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml @@ -1,13 +1,25 @@ --- -- name: Test +- name: Wipe and Install hosts: all gather_facts: false tasks: - - name: Install python - raw: test -e /usr/bin/python3 || apk add --no-cache python3 + - name: Install python + raw: test -e /usr/bin/python3 || apk update && apk add --no-cache python3 - - name: Gather facts - setup: - vars: - ansible_python_interpreter: /usr/bin/python3 + - name: Gather facts + setup: + vars: + ansible_python_interpreter: /usr/bin/python3 + + - name: Add community repository + raw: echo "http://dl-cdn.alpinelinux.org/alpine/v3.20/community/" >> /etc/apk/repositories + + - name: Install podman + raw: apk add --no-cache podman podman-compose + + - name: Setup podman + raw: rc-update add cgroups && rc-service cgroups start + + - name: Start webserver + raw: podman run --rm -dit --name my-apache-app -p 80:80 -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4 From bb1c6f274e8eee249c79c7ad600dccf6d05977e9 Mon Sep 17 00:00:00 2001 From: NoSpawnn Date: Fri, 30 May 2025 16:32:30 +0100 Subject: [PATCH 2/6] Remove redundant `apk update` --- repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml b/repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml index ad18cf5..03de791 100644 --- a/repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml +++ b/repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml @@ -5,7 +5,7 @@ tasks: - name: Install python - raw: test -e /usr/bin/python3 || apk update && apk add --no-cache python3 + raw: test -e /usr/bin/python3 || apk add --no-cache python3 - name: Gather facts setup: From 3d0572c7c97148c9f9aa0c2092c0130739cbfa72 Mon Sep 17 00:00:00 2001 From: NoSpawnn <78027161+NoSpawnn@users.noreply.github.com> Date: Fri, 30 May 2025 18:06:22 +0100 Subject: [PATCH 3/6] Create init_fixes.sh --- .../deploy/build/alpine/init_fixes.sh | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 repo-server-bootstrap-ncl-issue-20/deploy/build/alpine/init_fixes.sh diff --git a/repo-server-bootstrap-ncl-issue-20/deploy/build/alpine/init_fixes.sh b/repo-server-bootstrap-ncl-issue-20/deploy/build/alpine/init_fixes.sh new file mode 100644 index 0000000..5312d1d --- /dev/null +++ b/repo-server-bootstrap-ncl-issue-20/deploy/build/alpine/init_fixes.sh @@ -0,0 +1,20 @@ +# DNS ping +for i in $dns1 $dns2; do + ebegin "Awaiting accessible DNS at $i" + while ! ping -c 1 -w 1 -q "$i" > /dev/null 2>&1; do + sleep 1 + done + eend $? + + echo "nameserver $i" >> /etc/resolv.conf +done + +# Alpine mirror ping +if [[ -n "$ALPINE_REPO" ]] && [[ "$ALPINE_REPO" != "auto" ]]; then + local alpine_repo_domain=$(echo "$ALPINE_REPO" | sed -E 's#https?://([^/]+).*#\1#') + ebegin "Awaiting accessible Alpine repo at $alpine_repo_domain" + while ! ping -c 1 -w 1 -q "$alpine_repo_domain" > /dev/null 2>&1; do + sleep 1 + done + eend $? +fi From 891f1c5e28a46b7a46247c200d001fe5029cedab Mon Sep 17 00:00:00 2001 From: NoSpawnn <78027161+NoSpawnn@users.noreply.github.com> Date: Fri, 30 May 2025 18:06:40 +0100 Subject: [PATCH 4/6] Set static-iface in bootfile --- repo-server-bootstrap-ncl-issue-20/deploy/serve/www/bootfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repo-server-bootstrap-ncl-issue-20/deploy/serve/www/bootfile b/repo-server-bootstrap-ncl-issue-20/deploy/serve/www/bootfile index fc5db08..b603893 100644 --- a/repo-server-bootstrap-ncl-issue-20/deploy/serve/www/bootfile +++ b/repo-server-bootstrap-ncl-issue-20/deploy/serve/www/bootfile @@ -5,7 +5,7 @@ # https://wiki.alpinelinux.org/wiki/PXE_boot # --- Network configuration (static IP) --- -set static-iface +set static-iface eth0 set static-ip 192.168.0.248 set static-gw 192.168.0.1 set static-mask 255.255.255.0 From 25499bc7aeb93f38f16737ec46f2d1664772f92a Mon Sep 17 00:00:00 2001 From: NoSpawnn <78027161+NoSpawnn@users.noreply.github.com> Date: Fri, 30 May 2025 18:16:41 +0100 Subject: [PATCH 5/6] Fucntional playbook to create web server --- .../deploy/ansible/playbook.yml | 66 +++++++++++++++---- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml b/repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml index 03de791..3b54505 100644 --- a/repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml +++ b/repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml @@ -4,22 +4,60 @@ gather_facts: false tasks: - - name: Install python - raw: test -e /usr/bin/python3 || apk add --no-cache python3 + - name: Install python3 + raw: test -e /usr/bin/python3 || apk add --no-cache python3 - - name: Gather facts - setup: - vars: - ansible_python_interpreter: /usr/bin/python3 + - name: Gather facts + setup: + vars: + ansible_python_interpreter: /usr/bin/python3 - - name: Add community repository - raw: echo "http://dl-cdn.alpinelinux.org/alpine/v3.20/community/" >> /etc/apk/repositories + - name: Install openntpd + apk: + name: openntpd + state: present - - name: Install podman - raw: apk add --no-cache podman podman-compose + - name: Setup NTP + command: setup-ntp + args: + creates: /etc/ntpd.conf - - name: Setup podman - raw: rc-update add cgroups && rc-service cgroups start + - name: Add community repository + lineinfile: + path: /etc/apk/repositories + line: "http://dl-cdn.alpinelinux.org/alpine/v3.20/community/" + state: present - - name: Start webserver - raw: podman run --rm -dit --name my-apache-app -p 80:80 -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4 + - name: Install podman + apk: + name: + - podman + state: present + + - name: Enable and start cgroups service + service: + name: cgroups + enabled: true + state: started + + - name: Ensure /srv/www directory exists + file: + path: /srv/www + state: directory + + - name: Create index.html + copy: + dest: /srv/www/index.html + content: "Hello\n" + + - name: Start apache container with podman + containers.podman.podman_container: + name: apache + image: docker.io/library/httpd:2.4 + state: started + restart_policy: unless-stopped + detach: true + ports: + - "80:80" + volumes: + - /srv/www:/usr/local/apache2/htdocs/ From 257142f5218a11db81550ef39624d5d792f780c8 Mon Sep 17 00:00:00 2001 From: NoSpawnn <78027161+NoSpawnn@users.noreply.github.com> Date: Fri, 30 May 2025 19:08:22 +0100 Subject: [PATCH 6/6] Refactor playboks --- .../deploy/ansible/init-python.yml | 8 +++++ .../deploy/ansible/main.yml | 8 +++++ .../deploy/ansible/setup-os-env.yml | 19 ++++++++++ .../{playbook.yml => setup-webserver.yml} | 35 +++---------------- .../internal/runner/main.go | 2 +- 5 files changed, 40 insertions(+), 32 deletions(-) create mode 100644 repo-server-bootstrap-ncl-issue-20/deploy/ansible/init-python.yml create mode 100644 repo-server-bootstrap-ncl-issue-20/deploy/ansible/main.yml create mode 100644 repo-server-bootstrap-ncl-issue-20/deploy/ansible/setup-os-env.yml rename repo-server-bootstrap-ncl-issue-20/deploy/ansible/{playbook.yml => setup-webserver.yml} (51%) diff --git a/repo-server-bootstrap-ncl-issue-20/deploy/ansible/init-python.yml b/repo-server-bootstrap-ncl-issue-20/deploy/ansible/init-python.yml new file mode 100644 index 0000000..23c318e --- /dev/null +++ b/repo-server-bootstrap-ncl-issue-20/deploy/ansible/init-python.yml @@ -0,0 +1,8 @@ +- name: Init python + hosts: all + gather_facts: false + + tasks: + # We should try to inlcude python in the Alpine image by default + - name: Install python3 + raw: test -e /usr/bin/python3 || apk add --no-cache python3 diff --git a/repo-server-bootstrap-ncl-issue-20/deploy/ansible/main.yml b/repo-server-bootstrap-ncl-issue-20/deploy/ansible/main.yml new file mode 100644 index 0000000..78b234d --- /dev/null +++ b/repo-server-bootstrap-ncl-issue-20/deploy/ansible/main.yml @@ -0,0 +1,8 @@ +- name: Init python + import_playbook: init-python.yml + +- name: Setup OS environment + import_playbook: setup-os-env.yml + +- name: Setup webserver container + import_playbook: setup-webserver.yml diff --git a/repo-server-bootstrap-ncl-issue-20/deploy/ansible/setup-os-env.yml b/repo-server-bootstrap-ncl-issue-20/deploy/ansible/setup-os-env.yml new file mode 100644 index 0000000..8cf395c --- /dev/null +++ b/repo-server-bootstrap-ncl-issue-20/deploy/ansible/setup-os-env.yml @@ -0,0 +1,19 @@ +- name: Setup OS + hosts: all + + tasks: + - name: Install openntpd + community.general.apk: + name: openntpd + state: present + + - name: Setup NTP + command: setup-ntp + args: + creates: /etc/ntpd.conf + + - name: Add community repository + lineinfile: + path: /etc/apk/repositories + line: "http://dl-cdn.alpinelinux.org/alpine/v3.20/community/" + state: present diff --git a/repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml b/repo-server-bootstrap-ncl-issue-20/deploy/ansible/setup-webserver.yml similarity index 51% rename from repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml rename to repo-server-bootstrap-ncl-issue-20/deploy/ansible/setup-webserver.yml index 3b54505..5e444fb 100644 --- a/repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml +++ b/repo-server-bootstrap-ncl-issue-20/deploy/ansible/setup-webserver.yml @@ -1,37 +1,10 @@ ---- -- name: Wipe and Install +- name: Setup webserver container hosts: all - gather_facts: false tasks: - - name: Install python3 - raw: test -e /usr/bin/python3 || apk add --no-cache python3 - - - name: Gather facts - setup: - vars: - ansible_python_interpreter: /usr/bin/python3 - - - name: Install openntpd - apk: - name: openntpd - state: present - - - name: Setup NTP - command: setup-ntp - args: - creates: /etc/ntpd.conf - - - name: Add community repository - lineinfile: - path: /etc/apk/repositories - line: "http://dl-cdn.alpinelinux.org/alpine/v3.20/community/" - state: present - - - name: Install podman - apk: - name: - - podman + - name: Ensure podman is present + community.general.apk: + name: podman state: present - name: Enable and start cgroups service diff --git a/repo-server-bootstrap-ncl-issue-20/internal/runner/main.go b/repo-server-bootstrap-ncl-issue-20/internal/runner/main.go index 64c3623..5b4af61 100644 --- a/repo-server-bootstrap-ncl-issue-20/internal/runner/main.go +++ b/repo-server-bootstrap-ncl-issue-20/internal/runner/main.go @@ -168,7 +168,7 @@ func bootstrap(lom *lom.LOM) error { // Run ansible playbook fmt.Println("Running playbook") - cmd := exec.Command("ansible-playbook", "-i", addr+",", "--private-key", "/app/key", "./ansible/playbook.yml") + cmd := exec.Command("ansible-playbook", "-i", addr+",", "--private-key", "/app/key", "./ansible/main.yml") cmd.Env = append(cmd.Env, "ANSIBLE_SSH_COMMON_ARGS='-o StrictHostKeyChecking=no'") cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr