11---
2- - name : Verify runner_no_default_labels
2+ - name : Validate Repo runners
3+ user : ansible
34 hosts : all
4- gather_facts : false
5+ gather_facts : yes
6+ become : yes
7+ vars :
8+ runner_user : ansible
9+ github_repo : " {{ lookup('env', 'GITHUB_REPO') }}"
10+ github_account : " {{ lookup('env', 'GITHUB_ACCOUNT') }}"
11+ github_api_url : " https://api.github.com"
12+ access_token : " {{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
13+ runner_name : " {{ ansible_facts.hostname }}"
14+
515 tasks :
6- - name : Assert runner_no_default_labels is true
16+ - name : Check currently registered runners
17+ ansible.builtin.uri :
18+ url : " {{ github_api_url }}/repos/{{ github_owner | default(github_account) }}/{{ github_repo }}/actions/runners"
19+ headers :
20+ Authorization : " token {{ access_token }}"
21+ Accept : " application/vnd.github.v3+json"
22+ method : GET
23+ status_code : 200
24+ force_basic_auth : yes
25+ register : registered_runners
26+
27+ - name : Check Runner
728 ansible.builtin.assert :
829 that :
9- - hostvars[inventory_hostname]['runner_no_default_labels'] | bool
10- - name : Assert runner_labels contains testlabel
30+ - registered_runners.json.runners.0.status == "online"
31+ quiet : true
32+
33+ - debug :
34+ var : registered_runners.json.runners.0
35+
36+ - name : Set fact - current labels
37+ ansible.builtin.set_fact :
38+ current_labels : " {{ registered_runners.json.runners.0 | json_query('labels[*].name') | list }}"
39+
40+ - name : Check Labels (skipped if labels are OK)
1141 ansible.builtin.assert :
1242 that :
13- - ' testlabel' in hostvars[inventory_hostname]['runner_labels']
43+ - current_labels == ['testlabel1', 'testlabel2']
44+ fail_msg : " Expected only the custom labels 'testlabel1' and 'testlabel2', but got {{ current_labels }}"
0 commit comments