Skip to content

Commit

Permalink
Merge branch 'develop' into use-ansible-facts
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhodgkiss authored Oct 3, 2023
2 parents 2bf0e5e + b49d739 commit 09dfbce
Show file tree
Hide file tree
Showing 23 changed files with 141 additions and 114 deletions.
4 changes: 4 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
skip_list:
- '106'
- ignore-errors
- yaml[truthy]
exclude_paths:
- .github/workflows/
13 changes: 10 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,32 @@ on:
branches:
- master
- main
- devel*

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
env:
ANSIBLE_ROLE: monolithprojects.github_actions_runner
SUITE: default
steps:
- name: Check out the codebase.
uses: actions/checkout@v3
with:
path: "${{ github.repository }}"
path: ${{ env.ANSIBLE_ROLE }}

- name: Set up Python 3.
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install test dependencies.
run: pip3 install ansible-lint yamllint
run: |
pip3 install ansible-lint yamllint
[ -f molecule/${SUITE}/requirements.yml ] && ansible-galaxy install -r molecule/${SUITE}/requirements.yml
{ echo '[defaults]'; echo 'callbacks_enabled = profile_tasks, timer'; echo 'roles_path = ../:/home/runner/.ansible/roles'; echo 'ansible_python_interpreter: /usr/bin/python3'; } >> ansible.cfg
- name: Lint code.
run: |
ansible-lint --exclude molecule/ --exclude .github/
cd $GITHUB_WORKSPACE/$ANSIBLE_ROLE && ansible-lint --exclude molecule/ --exclude .github/
1 change: 1 addition & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
- master
- devel*

jobs:
pre-commit:
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ name: molecule test
on:
pull_request:
branches:
- master
- main
- master
- main
- devel*
types: [opened, synchronize, reopened]
paths:
- 'defaults/**'
Expand Down Expand Up @@ -49,7 +50,10 @@ jobs:
python-version: '3.x'

- name: Install test dependencies
run: pip3 install ansible docker molecule molecule-plugins[docker] "requests<2.29.2" jmespath
run: |
pip3 install ansible docker molecule molecule-plugins[docker] "requests<2.29.2" jmespath
# https://github.com/ansible/molecule/issues/4017
pip3 install ansible ansible-core==2.15.2 ansible-compat==4.1.5 'molecule<6' molecule-plugins[docker] docker
- name: Run Molecule test - repo
run: molecule test --scenario-name repo
Expand Down
10 changes: 5 additions & 5 deletions molecule/custom_env/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
hosts: all
become: yes
vars:
- runner_user: ansible
- github_repo: ansible-github_actions_runner-testrepo
- github_account: monolithprojects-testorg
- runner_state: absent
runner_user: ansible
github_repo: ansible-github_actions_runner-testrepo
github_account: monolithprojects-testorg
runner_state: absent
roles:
- ansible-github_actions_runner
- monolithprojects.github_actions_runner
14 changes: 7 additions & 7 deletions molecule/custom_env/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
gather_facts: yes
become: yes
vars:
- runner_user: ansible
- github_repo: ansible-github_actions_runner-testrepo
- github_account: monolithprojects-testorg
- runner_version: "latest"
- runner_labels:
runner_user: ansible
github_repo: ansible-github_actions_runner-testrepo
github_account: monolithprojects-testorg
runner_version: "latest"
runner_labels:
- label1
- repo-runner
- custom_env: |
custom_env: |
# HTTPS_PROXY=YOUR_URL_HERE
roles:
- robertdebock.epel
- ansible-github_actions_runner
- monolithprojects.github_actions_runner
4 changes: 3 additions & 1 deletion molecule/custom_env/requirements.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---
- role: robertdebock.epel

roles:
- name: robertdebock.epel
version: 3.0.1
25 changes: 13 additions & 12 deletions molecule/custom_env/verify.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
---
- name: validate Repo runners
- name: Validate Repo runners
user: ansible
hosts: all
gather_facts: yes
become: yes
vars:
- runner_user: ansible
- github_repo: ansible-github_actions_runner-testrepo
- github_account: monolithprojects-testorg
- github_api_url: "https://api.github.com"
- access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
- runner_name: ubuntu16-latest
runner_user: ansible
github_repo: ansible-github_actions_runner-testrepo
github_account: monolithprojects-testorg
github_api_url: "https://api.github.com"
access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
runner_name: ubuntu16-latest

tasks:
- name: Check currently registered runners
uri:
ansible.builtin.uri:
url: "{{ github_api_url }}/repos/{{ github_owner | default(github_account) }}/{{ github_repo }}/actions/runners"
headers:
Authorization: "token {{ access_token }}"
Expand All @@ -24,23 +24,24 @@
force_basic_auth: yes
register: registered_runners

- debug:
- name: Debug | var registered_runners
ansible.builtin.debug:
var: registered_runners.json.runners

- name: Check Runner
assert:
ansible.builtin.assert:
that:
- runner_name in registered_runners.json.runners|map(attribute='name')|list
- registered_runners.json.runners|map(attribute='status') == ["online"]
quiet: true

- name: Check Labels (skipped if labels are OK)
fail:
ansible.builtin.fail:
msg: Woops some labels differ "{{ (registered_runners.json.runners.0 | json_query('labels[*].name') | difference(['self-hosted', 'Linux', 'X64', 'label1', 'repo-runner'])) }}"
when: not (registered_runners.json.runners.0 | json_query('labels[*].name') | list ) == (['self-hosted', 'Linux', 'X64', 'label1', 'repo-runner'] | list)

- name: Check custom env file is configured
lineinfile:
ansible.builtin.lineinfile:
dest: /opt/actions-runner/.env
line: "# HTTPS_PROXY=YOUR_URL_HERE"
check_mode: yes
Expand Down
12 changes: 6 additions & 6 deletions molecule/default/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
hosts: all
become: yes
vars:
- runner_user: ansible
- github_repo: ansible-github_actions_runner-testrepo
- github_account: monolithprojects-testorg
- runner_state: absent
- runner_name: test_name
runner_user: ansible
github_repo: ansible-github_actions_runner-testrepo
github_account: monolithprojects-testorg
runner_state: absent
runner_name: test_name
roles:
- ansible-github_actions_runner
- monolithprojects.github_actions_runner
20 changes: 10 additions & 10 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
gather_facts: yes
become: yes
vars:
- runner_user: ansible
- github_repo: ansible-github_actions_runner-testrepo
- github_account: monolithprojects-testorg
- runner_version: "latest"
- runner_name: test_name
- runner_on_ghes: yes
- reinstall_runner: false
- hide_sensitive_logs: no
- runner_labels:
runner_user: ansible
github_repo: ansible-github_actions_runner-testrepo
github_account: monolithprojects-testorg
runner_version: "latest"
runner_name: test_name
runner_on_ghes: yes
reinstall_runner: false
hide_sensitive_logs: no
runner_labels:
- label1
- repo-runner
roles:
- robertdebock.epel
- ansible-github_actions_runner
- monolithprojects.github_actions_runner
4 changes: 3 additions & 1 deletion molecule/default/requirements.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---
- role: robertdebock.epel

roles:
- name: robertdebock.epel
version: 3.0.1
23 changes: 12 additions & 11 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
---
- name: validate Repo runners
- name: Validate Repo runners
user: ansible
hosts: all
gather_facts: yes
become: yes
vars:
- runner_user: ansible
- github_repo: ansible-github_actions_runner-testrepo
- github_account: monolithprojects-testorg
- github_api_url: "https://api.github.com"
- access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
- runner_name: ubuntu16-latest
runner_user: ansible
github_repo: ansible-github_actions_runner-testrepo
github_account: monolithprojects-testorg
github_api_url: "https://api.github.com"
access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
runner_name: ubuntu16-latest

tasks:
- name: Check currently registered runners
uri:
ansible.builtin.uri:
url: "{{ github_api_url }}/repos/{{ github_owner | default(github_account) }}/{{ github_repo }}/actions/runners"
headers:
Authorization: "token {{ access_token }}"
Expand All @@ -24,17 +24,18 @@
force_basic_auth: yes
register: registered_runners

- debug:
- name: Debug | var registered_runners
ansible.builtin.debug:
var: registered_runners.json.runners

- name: Check Runner
assert:
ansible.builtin.assert:
that:
- runner_name in registered_runners.json.runners|map(attribute='name')|list
- registered_runners.json.runners|map(attribute='status') == ["online"]
quiet: true

- name: Check Labels (skipped if labels are OK)
fail:
ansible.builtin.fail:
msg: Woops some labels differ "{{ (registered_runners.json.runners.0 | json_query('labels[*].name') | difference(['self-hosted', 'Linux', 'X64', 'label1', 'repo-runner'])) }}"
when: not (registered_runners.json.runners.0 | json_query('labels[*].name') | list ) == (['self-hosted', 'Linux', 'X64', 'label1', 'repo-runner'] | list)
10 changes: 5 additions & 5 deletions molecule/org/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
hosts: all
become: yes
vars:
- runner_user: ansible
- github_account: monolithprojects-testorg
- runner_org: yes
- runner_state: absent
runner_user: ansible
github_account: monolithprojects-testorg
runner_org: yes
runner_state: absent
roles:
- ansible-github_actions_runner
- monolithprojects.github_actions_runner
12 changes: 6 additions & 6 deletions molecule/org/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
hosts: all
become: yes
vars:
- runner_user: ansible
- github_account: monolithprojects-testorg
- runner_org: yes
- runner_state: "stopped"
- runner_version: "2.303.0"
runner_user: ansible
github_account: monolithprojects-testorg
runner_org: yes
runner_state: "stopped"
runner_version: "2.303.0"
roles:
- robertdebock.epel
- ansible-github_actions_runner
- monolithprojects.github_actions_runner
4 changes: 3 additions & 1 deletion molecule/org/requirements.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---
- role: robertdebock.epel

roles:
- name: robertdebock.epel
version: 3.0.1
20 changes: 10 additions & 10 deletions molecule/org/verify.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
---
- name: validate Repo runners
- name: Validate Repo runners
user: ansible
hosts: all
gather_facts: yes
become: yes
vars:
- runner_user: ansible
- github_account: monolithprojects-testorg
- runner_org: yes
- github_api_url: "https://api.github.com"
- access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
- runner_name: "{{ ansible_facts.hostname }}"
runner_user: ansible
github_account: monolithprojects-testorg
runner_org: yes
github_api_url: "https://api.github.com"
access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
runner_name: "{{ ansible_facts.hostname }}"

tasks:
- name: Give the runners a minute
pause:
ansible.builtin.pause:
seconds: 30

- name: Check currently registered runners
uri:
ansible.builtin.uri:
url: "{{ github_api_url }}/orgs/{{ github_owner | default(github_account) }}/actions/runners"
headers:
Authorization: "token {{ access_token }}"
Expand All @@ -29,7 +29,7 @@
register: registered_runners

- name: Check Runner
assert:
ansible.builtin.assert:
that:
- runner_name in registered_runners.json.runners|map(attribute='name')|list
quiet: true
10 changes: 5 additions & 5 deletions molecule/repo/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
hosts: all
become: yes
vars:
- runner_user: ansible
- github_repo: ansible-github_actions_runner-testrepo
- github_account: monolithprojects-testorg
- runner_state: absent
runner_user: ansible
github_repo: ansible-github_actions_runner-testrepo
github_account: monolithprojects-testorg
runner_state: absent
roles:
- ansible-github_actions_runner
- monolithprojects.github_actions_runner
Loading

0 comments on commit 09dfbce

Please sign in to comment.