From e9f7f639a581395e78cb7898e77ae3b36a7dd4b6 Mon Sep 17 00:00:00 2001 From: Ihor Solodrai Date: Tue, 2 Jun 2026 12:21:03 -0700 Subject: [PATCH] ansible: prepare runner provisioning for Ubuntu bare-metal hosts Add support for provisioning Ubuntu 24.04 (Noble) bare-metal AWS hosts as runners, alongside the existing Amazon Linux 2 (RedHat family) and s390x LinuxONE (Debian family) hosts, without changing behavior for either. - base: start (and enable) the docker service on Debian hosts, mirroring the RedHat path. On Ubuntu cloud-init first boot docker.io may not be up yet when qemu-user-static / the runner units need it; idempotent on s390x. - base/runner: make the apt installs resilient to first-boot dpkg-lock contention from apt-daily/unattended-upgrades (lock_timeout + retries). - runner: derive runner names from the EC2 instance ID on all EC2 hosts (system_vendor == "Amazon EC2"), not just Amazon Linux, so Ubuntu EC2 hosts get stable, collision-free names. Non-EC2 hosts (s390x) still skip the metadata lookup; the retained Amazon-distribution clause keeps AL2 behavior identical. - add ansible/requirements.yml (community.docker, amazon.aws) and document it, for the manual operator workflow / ansible-core installs. - fix stale runner_libbpf_ci_repo_branch defaults (master -> main). Signed-off-by: Ihor Solodrai --- ansible/README.md | 11 +++++++++++ ansible/inventory_example.yml | 2 +- ansible/requirements.yml | 4 ++++ ansible/roles/base/tasks/setup-Debian.yml | 12 ++++++++++++ ansible/roles/runner/defaults/main.yml | 2 +- ansible/roles/runner/tasks/main.yml | 17 ++++++++++++----- 6 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 ansible/requirements.yml diff --git a/ansible/README.md b/ansible/README.md index e0ad33e8..34a0d2d0 100644 --- a/ansible/README.md +++ b/ansible/README.md @@ -5,6 +5,17 @@ sudo dnf install -y ansible ``` +## Required collections + +The playbook uses modules from `community.docker` (`docker_login`) and `amazon.aws` +(`ec2_metadata_facts`). The `ansible` metapackage bundles these; if you installed +`ansible-core` only, install them explicitly: + +``` +ansible-galaxy collection install -r ansible/requirements.yml +``` + + ## Inventory The [inventory](https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html) is where we define our hosts, hostgroup, possibly variable... diff --git a/ansible/inventory_example.yml b/ansible/inventory_example.yml index f4f9331a..f8be437f 100644 --- a/ansible/inventory_example.yml +++ b/ansible/inventory_example.yml @@ -61,7 +61,7 @@ all: vars: ansible_ssh_common_args: -o 'ProxyCommand ......' runner_libbpf_ci_repo_url: https://github.com/libbpf/ci - runner_libbpf_ci_repo_branch: master + runner_libbpf_ci_repo_branch: main runner_gh_apps: - name: kernel-patches-runner id: a-github-app-id diff --git a/ansible/requirements.yml b/ansible/requirements.yml new file mode 100644 index 00000000..b1d01ce2 --- /dev/null +++ b/ansible/requirements.yml @@ -0,0 +1,4 @@ +--- +collections: + - name: community.docker + - name: amazon.aws diff --git a/ansible/roles/base/tasks/setup-Debian.yml b/ansible/roles/base/tasks/setup-Debian.yml index 12b97a3f..bb510d54 100644 --- a/ansible/roles/base/tasks/setup-Debian.yml +++ b/ansible/roles/base/tasks/setup-Debian.yml @@ -5,8 +5,20 @@ state: present name: "{{ base_packages }}" update_cache: yes + lock_timeout: 300 + register: base_packages_install + until: base_packages_install is succeeded + retries: 30 + delay: 10 tags: [install] +- name: Start docker + become: true + service: + name: docker + state: started + enabled: true + - name: Gather the package facts ansible.builtin.package_facts: diff --git a/ansible/roles/runner/defaults/main.yml b/ansible/roles/runner/defaults/main.yml index 6f508681..33e8a22d 100644 --- a/ansible/roles/runner/defaults/main.yml +++ b/ansible/roles/runner/defaults/main.yml @@ -15,7 +15,7 @@ runner_docker_mount_volume: false runner_gh_tokens: owner/repository: gh token for owner/repository runner_libbpf_ci_repo_url: https://github.com/libbpf/ci.git -runner_libbpf_ci_repo_branch: master +runner_libbpf_ci_repo_branch: main runner_repo_list: - {name: owner1/repository1, instances: 2} - {name: owner1/repository2, instances: 1} diff --git a/ansible/roles/runner/tasks/main.yml b/ansible/roles/runner/tasks/main.yml index dff4102d..0e151f8e 100644 --- a/ansible/roles/runner/tasks/main.yml +++ b/ansible/roles/runner/tasks/main.yml @@ -18,6 +18,11 @@ state: present name: python3-docker update_cache: yes + lock_timeout: 300 + register: python3_docker_install + until: python3_docker_install is succeeded + retries: 30 + delay: 10 when: ansible_os_family == 'Debian' - name: Create runner directory @@ -75,10 +80,12 @@ set_fact: runner_name_prefix: "{{ '%s-' | format(runner_prefix) if runner_prefix }}{{ ansible_hostname }}" -# When running on Amazon Linux hosts, we override the runner_name_prefix with the ec2's instance ID. -# When testing in Amazon Linux VMs, the `Load ec2 metadata facts` task will fail and we will fallback -# on using hostname. -- name: Set runner_name_prefix to instance ID for Amazon hosts +# On EC2 hosts (Amazon Linux metal and Ubuntu metal alike) we override the runner_name_prefix +# with the ec2's instance ID for stable, collision-free runner names. Non-EC2 hosts (e.g. s390x +# LinuxONE, vendor "IBM") are skipped so we never block on the 169.254.169.254 metadata endpoint. +# If amazon.aws is missing or the metadata endpoint is unreachable, `ignore_errors` lets us fall +# back to the hostname-based prefix set above. +- name: Set runner_name_prefix to instance ID for EC2 hosts block: - name: Load ec2 metadata facts amazon.aws.ec2_metadata_facts: @@ -86,7 +93,7 @@ - name: Set runner name prefix with instance ID set_fact: runner_name_prefix: "{{ '%s-' | format(runner_prefix) if runner_prefix }}{{ ansible_ec2_instance_id }}" - when: ansible_distribution == 'Amazon' + when: ansible_system_vendor == 'Amazon EC2' or ansible_distribution == 'Amazon' ignore_errors: yes - name: Generate runner env