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/playbook.yml b/repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml deleted file mode 100644 index bb2b500..0000000 --- a/repo-server-bootstrap-ncl-issue-20/deploy/ansible/playbook.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -- name: Test - hosts: all - gather_facts: false - - tasks: - - name: Install python - raw: test -e /usr/bin/python3 || apk add --no-cache python3 - - - name: Gather facts - setup: - vars: - ansible_python_interpreter: /usr/bin/python3 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/setup-webserver.yml b/repo-server-bootstrap-ncl-issue-20/deploy/ansible/setup-webserver.yml new file mode 100644 index 0000000..5e444fb --- /dev/null +++ b/repo-server-bootstrap-ncl-issue-20/deploy/ansible/setup-webserver.yml @@ -0,0 +1,36 @@ +- name: Setup webserver container + hosts: all + + tasks: + - name: Ensure podman is present + community.general.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/ 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 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 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