Skip to content

Commit 63d5595

Browse files
committed
ansible: Set runner_name_prefix to the host's hostname by default
For Amazon Linux running in EC2, the prefix get overwritten by the instance ID instead. We try to do this in a block where failure are ignored. This code is only run when the host OS is Amazon Linux. Failure to access the EC2 endpoint to discover the host metadata will result in the host defaulting to use its hostname. This is useful when running an Amazon Linux host in a VM for local testing. Signed-off-by: Manu Bretelle <[email protected]>
1 parent 30c97ee commit 63d5595

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

ansible/roles/runner/tasks/main.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,29 @@
6060
runners: "{{ runners|default([]) + [ {'gh_app_id': 0, 'normalized': item.name | replace('/','-'), 'workers': range(item.instances) | list } | combine(item) ] }}"
6161
with_items: "{{ runner_repo_list }}"
6262

63-
- name: Generate runner environment file
63+
- name: Set runner name prefix
64+
set_fact:
65+
runner_name_prefix: "{{ '%s-' | format(runner_prefix) if runner_prefix }}{{ ansible_hostname }}"
66+
67+
# When running on Amazon Linux hosts, we override the runner_name_prefix with the ec2's instance ID.
68+
# When testing in Amazon Linux VMs, the `Load ec2 metadata facts` task will fail and we will fallback
69+
# on using hostname.
70+
- name: Set runner_name_prefix to instance ID for Amazon hosts
6471
block:
6572
- name: Load ec2 metadata facts
6673
amazon.aws.ec2_metadata_facts:
6774

68-
- name: Set runner name prefix
75+
- name: Set runner name prefix with instance ID
6976
set_fact:
7077
runner_name_prefix: "{{ '%s-' | format(runner_prefix) if runner_prefix }}{{ ansible_ec2_instance_id }}"
71-
72-
rescue:
73-
- name: Set runner name prefix
74-
set_fact:
75-
runner_name_prefix: "{{ '%s-' | format(runner_prefix) if runner_prefix }}{{ ansible_hostname }}"
78+
when: ansible_distribution == 'Amazon'
79+
ignore_errors: yes
7680

7781
# Build docker images
7882
- include_tasks: main-s390x.yml
7983
when: ansible_architecture == 's390x'
8084

81-
- name: Generate runner env outside AWS
85+
- name: Generate runner env
8286
become: yes
8387
ansible.builtin.copy:
8488
dest: "{{ runner_base_dir }}/actions-runner-{{ item.0.normalized }}-{{ 'worker-%02d.env' | format(item.1) }}"

0 commit comments

Comments
 (0)