diff --git a/.github/workflows/galaxy.yml b/.github/workflows/galaxy.yml index 4d62038..f6ca6a7 100644 --- a/.github/workflows/galaxy.yml +++ b/.github/workflows/galaxy.yml @@ -8,7 +8,7 @@ on: jobs: release: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - name: galaxy uses: robertdebock/galaxy-action@1.0.1 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 9f21eff..e10b34b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -11,7 +11,7 @@ on: types: [opened, synchronize, reopened] jobs: lint: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 strategy: fail-fast: true steps: @@ -20,6 +20,6 @@ jobs: with: path: "${{ github.repository }}" - name: Molecule for Ansible - lint - uses: MonolithProjects/action-molecule@v1.4.0 + uses: MonolithProjects/action-molecule@v1.4.1 with: molecule_command: lint diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 35bf7fd..d3a366d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,41 +3,61 @@ name: molecule test on: pull_request: branches: - - master + - main types: [opened, synchronize, reopened] schedule: - cron: '0 6 * * 0' jobs: repo: name: Test Repo Runner - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 strategy: - fail-fast: true + fail-fast: false + matrix: + config: + - os: "centos7" + tag: "latest" + - os: "centos8" + tag: "latest" + - os: "debian9" + tag: "latest" + - os: "debian10" + tag: "latest" + - os: "fedora33" + tag: "latest" + - os: "ubuntu18" + tag: "latest" + - os: "ubuntu20" + tag: "latest" steps: - name: checkout uses: actions/checkout@v2 with: path: "${{ github.repository }}" - name: Molecule for Ansible - GHR Repository - uses: MonolithProjects/action-molecule@v1.4.0 + uses: MonolithProjects/action-molecule@v1.4.1 env: PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} with: + os: ${{ matrix.config.os }} + tag: ${{ matrix.config.tag }} molecule_command: test + scenario: repo + org: name: Test Org Runner - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 strategy: - fail-fast: true + fail-fast: false steps: - name: checkout uses: actions/checkout@v2 with: path: "${{ github.repository }}" - name: Molecule for Ansible - GHR Organization - uses: MonolithProjects/action-molecule@v1.4.0 + uses: MonolithProjects/action-molecule@v1.4.1 env: PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} with: molecule_command: test - scenario: organization \ No newline at end of file + scenario: org \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fb99125..1c459d2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -31,9 +31,10 @@ cd ansible-github_actions_runner molecule test ``` +> You will need to edit the files in `molecule/default` directory (please do not commit those changes) + ## 5. Create a pull request Please create a pull request into the `develop` branch. Here is [how to do it](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork). - Please consider to [sponsor](https://github.com/sponsors/monolithprojects) me :-) \ No newline at end of file diff --git a/README.md b/README.md index 886fab3..0d9f3f8 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Personal Access Token for GitHub account can be created [here](https://github.co * ARM, ARM64 (dependencies installation is not covered by this role) * AMD64, x86_64 -## Weekly tested on: +## Tested on: * CentOS/RHEL 7,8 * Debian 9,10 @@ -82,7 +82,7 @@ runner_org: no # Name to assign to this runner in GitHub (System hostname as default) runner_name: "{{ ansible_hostname }}" -# Labels to apply to the runner +# Labels to apply to the runner. For examle "'label1','label2'" runner_labels: "''" # Custom service name when usign Github Enterprise server diff --git a/defaults/main.yml b/defaults/main.yml index 186468b..8470ff3 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -35,7 +35,7 @@ runner_org: no # Name to assign to this runner in GitHub (System hostname as default) runner_name: "{{ ansible_hostname }}" -# Labels to apply to the runner +# Labels to apply to the runner. For examle "'label1','label2'" runner_labels: "''" # Custom service name when usign Github Enterprise server diff --git a/handlers/main.yml b/handlers/main.yml index 01db756..cff7cd6 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,5 +1,5 @@ --- -# handlers file for ansible-github_actions_runner +# handlers file for ansible-github_actions_runner (currently not used) - name: Restart runner service service: name: "{{ runner_service }}" diff --git a/molecule/default/Dockerfile.j2 b/molecule/default/Dockerfile.j2 deleted file mode 100644 index dfdc410..0000000 --- a/molecule/default/Dockerfile.j2 +++ /dev/null @@ -1,31 +0,0 @@ -# Molecule managed - -{% if item.registry is defined %} -FROM {{ item.registry.url }}/{{ item.image }} -{% else %} -FROM {{ item.image }} -{% endif %} - -{% if item.env is defined %} -{% for var, value in item.env.items() %} -{% if value %} -ENV {{ var }} {{ value }} -{% endif %} -{% endfor %} -{% endif %} - -RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates iproute2 && apt-get clean; \ - elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash iproute && dnf clean all; \ - elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash iproute && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ - elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml iproute2 && zypper clean -a; \ - elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ - elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates iproute2 && xbps-remove -O; fi - -ENV ANSIBLE_USER=ansible SUDO_GROUP=wheel DEPLOY_GROUP=deployer -RUN set -xe \ - && groupadd -r ${ANSIBLE_USER} \ - && groupadd -r ${DEPLOY_GROUP} \ - && useradd -m -g ${ANSIBLE_USER} ${ANSIBLE_USER} \ - && usermod -aG ${SUDO_GROUP} ${ANSIBLE_USER} \ - && usermod -aG ${DEPLOY_GROUP} ${ANSIBLE_USER} \ - && sed -i "/^%${SUDO_GROUP}/s/ALL\$/NOPASSWD:ALL/g" /etc/sudoers \ No newline at end of file diff --git a/molecule/default/INSTALL.rst b/molecule/default/INSTALL.rst deleted file mode 100644 index 6a44bde..0000000 --- a/molecule/default/INSTALL.rst +++ /dev/null @@ -1,22 +0,0 @@ -******* -Docker driver installation guide -******* - -Requirements -============ - -* Docker Engine - -Install -======= - -Please refer to the `Virtual environment`_ documentation for installation best -practices. If not using a virtual environment, please consider passing the -widely recommended `'--user' flag`_ when invoking ``pip``. - -.. _Virtual environment: https://virtualenv.pypa.io/en/latest/ -.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site - -.. code-block:: bash - - $ pip install 'molecule[docker]' diff --git a/molecule/default/cleanup.yml b/molecule/default/cleanup.yml index d42361e..15c5281 100644 --- a/molecule/default/cleanup.yml +++ b/molecule/default/cleanup.yml @@ -6,7 +6,7 @@ vars: - runner_user: ansible - github_repo: ansible-github_actions_runner-testrepo - - github_account: monolithprojects + - github_account: monolithprojects-testorg - runner_state: absent roles: - ansible-github_actions_runner \ No newline at end of file diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 15972d2..8272c67 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -1,5 +1,5 @@ --- -- name: Install +- name: Dev test playbook user: ansible hosts: all gather_facts: yes @@ -7,23 +7,9 @@ vars: - runner_user: ansible - github_repo: ansible-github_actions_runner-testrepo - - github_account: monolithprojects - - runner_version: "latest" - - reinstall_runner: yes - roles: - - robertdebock.epel - - ansible-github_actions_runner - -- name: Idempotence test - user: ansible - hosts: all - become: yes - gather_facts: yes - vars: - - runner_user: ansible - - github_repo: ansible-github_actions_runner-testrepo - - github_account: monolithprojects + - github_account: monolithprojects-testorg - runner_version: "latest" + - runner_labels: "'test1','test2'" roles: - robertdebock.epel - ansible-github_actions_runner \ No newline at end of file diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index b39d7e9..06c095b 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -1,42 +1,20 @@ --- -driver: - name: docker +provisioner: + name: ansible + playbooks: + converge: converge.yml + cleanup: cleanup.yml + verify: verify.yml +dependency: + name: galaxy lint: | yamllint . - ansible-lint + ansible-lint . +driver: + name: docker platforms: - - name: CentOS7 - image: monolithprojects/systemd-centos7:latest - command: /sbin/init - tmpfs: - - /run - - /tmp - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: yes - pre_build_image: yes - - name: CentOS8 - image: monolithprojects/systemd-centos8:latest - command: /sbin/init - tmpfs: - - /run - - /tmp - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: yes - pre_build_image: yes - - name: Fedora32 - image: monolithprojects/systemd-fedora32:latest - command: /sbin/init - tmpfs: - - /run - - /tmp - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: yes - pre_build_image: yes - - name: Fedora33 - image: monolithprojects/systemd-fedora33:latest + - name: "${os:-ubuntu16}-${tag:-latest}" + image: "${namespace:-monolithprojects}/systemd-${os:-ubuntu16}:${tag:-latest}" command: /sbin/init tmpfs: - /run @@ -45,70 +23,8 @@ platforms: - /sys/fs/cgroup:/sys/fs/cgroup:ro privileged: yes pre_build_image: yes - - name: Ubuntu16 - image: monolithprojects/systemd-ubuntu16:latest - command: /sbin/init - tmpfs: - - /run - - /tmp - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: yes - pre_build_image: yes - - name: Ubuntu18 - image: monolithprojects/systemd-ubuntu18:latest - command: /sbin/init - tmpfs: - - /run - - /tmp - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: yes - pre_build_image: yes - - name: Ubuntu20 - image: monolithprojects/systemd-ubuntu20:latest - command: /sbin/init - tmpfs: - - /run - - /tmp - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: yes - pre_build_image: yes - - name: Debian9 - image: monolithprojects/systemd-debian9:latest - command: /sbin/init - tmpfs: - - /run - - /tmp - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: yes - pre_build_image: yes - - name: Debian10 - image: monolithprojects/systemd-debian10:latest - command: /sbin/init - tmpfs: - - /run - - /tmp - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: yes - pre_build_image: yes -provisioner: - name: ansible - playbooks: - converge: converge.yml - cleanup: cleanup.yml - log: false verifier: - name: testinfra - directory: tests -dependency: - name: galaxy - options: - ignore-certs: True - ignore-errors: True + name: ansible scenario: name: default test_sequence: @@ -117,8 +33,8 @@ scenario: - destroy - syntax - create - # - prepare - converge - # - idempotence + - idempotence + - verify - cleanup - destroy \ No newline at end of file diff --git a/molecule/default/requirements.yml b/molecule/default/requirements.yml index 6e10ff7..9768a73 100644 --- a/molecule/default/requirements.yml +++ b/molecule/default/requirements.yml @@ -1,3 +1,3 @@ --- - role: robertdebock.epel - version: 2.5.4 + version: 3.0.1 diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py deleted file mode 100644 index c62900f..0000000 --- a/molecule/default/tests/test_default.py +++ /dev/null @@ -1,13 +0,0 @@ -import os - -import testinfra.utils.ansible_runner - -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE'] -).get_hosts('all') - - -def test_hosts_file(host): - f = host.file('/opt/actions-runner') - - assert f.exists \ No newline at end of file diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml new file mode 100644 index 0000000..43cf7c6 --- /dev/null +++ b/molecule/default/verify.yml @@ -0,0 +1,35 @@ +--- +- 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 + + tasks: + - name: Check currently registered runners + uri: + url: "{{ github_api_url }}/repos/{{ github_owner | default(github_account) }}/{{ github_repo }}/actions/runners" + headers: + Authorization: "token {{ access_token }}" + Accept: "application/vnd.github.v3+json" + method: GET + status_code: 200 + force_basic_auth: yes + register: registered_runners + + - debug: + var: registered_runners.json.runners + + - name: Check Runner + assert: + that: + - runner_name in registered_runners.json.runners|map(attribute='name')|list + - registered_runners.json.runners|map(attribute='status') == ["online"] + quiet: true \ No newline at end of file diff --git a/molecule/organization/cleanup.yml b/molecule/org/cleanup.yml similarity index 100% rename from molecule/organization/cleanup.yml rename to molecule/org/cleanup.yml index ee00815..62db318 100644 --- a/molecule/organization/cleanup.yml +++ b/molecule/org/cleanup.yml @@ -6,7 +6,7 @@ vars: - runner_user: ansible - github_account: monolithprojects-testorg - - runner_state: absent - runner_org: yes + - runner_state: absent roles: - ansible-github_actions_runner \ No newline at end of file diff --git a/molecule/org/converge.yml b/molecule/org/converge.yml new file mode 100644 index 0000000..33c6556 --- /dev/null +++ b/molecule/org/converge.yml @@ -0,0 +1,14 @@ +--- +- name: Install Org Runner + user: ansible + hosts: all + become: yes + vars: + - runner_user: ansible + - github_account: monolithprojects-testorg + - runner_org: yes + - runner_state: "stopped" + - runner_version: "2.274.2" + roles: + - robertdebock.epel + - ansible-github_actions_runner \ No newline at end of file diff --git a/molecule/org/molecule.yml b/molecule/org/molecule.yml new file mode 100644 index 0000000..daac821 --- /dev/null +++ b/molecule/org/molecule.yml @@ -0,0 +1,40 @@ +--- +provisioner: + name: ansible + playbooks: + converge: converge.yml + cleanup: cleanup.yml + verify: verify.yml +dependency: + name: galaxy +lint: | + yamllint . + ansible-lint . +driver: + name: docker +platforms: + - name: "${os:-ubuntu16}-${tag:-latest}" + image: "${namespace:-monolithprojects}/systemd-${os:-ubuntu16}:${tag:-latest}" + command: /sbin/init + tmpfs: + - /run + - /tmp + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: yes + pre_build_image: yes +verifier: + name: ansible +scenario: + name: org + test_sequence: + - dependency + - lint + - destroy + - syntax + - create + - converge + - idempotence + - verify + - cleanup + - destroy \ No newline at end of file diff --git a/molecule/organization/requirements.yml b/molecule/org/requirements.yml similarity index 63% rename from molecule/organization/requirements.yml rename to molecule/org/requirements.yml index 6e10ff7..9768a73 100644 --- a/molecule/organization/requirements.yml +++ b/molecule/org/requirements.yml @@ -1,3 +1,3 @@ --- - role: robertdebock.epel - version: 2.5.4 + version: 3.0.1 diff --git a/molecule/org/verify.yml b/molecule/org/verify.yml new file mode 100644 index 0000000..066bb1b --- /dev/null +++ b/molecule/org/verify.yml @@ -0,0 +1,42 @@ +--- +- 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_hostname }}" + + tasks: + - name: Give the runners a minute + pause: + seconds: 30 + + - name: Check currently registered runners + uri: + url: "{{ github_api_url }}/orgs/{{ github_owner | default(github_account) }}/actions/runners" + headers: + Authorization: "token {{ access_token }}" + Accept: "application/vnd.github.v3+json" + method: GET + status_code: 200 + force_basic_auth: yes + register: registered_runners + + - name: Check Runner + assert: + that: + - runner_name in registered_runners.json.runners|map(attribute='name')|list + - registered_runners.json.runners|map(attribute='status') == ["offline"] + quiet: true + + - debug: + var: registered_runners.json.runners|map(attribute='name') + + - debug: + var: registered_runners.json.runners|map(attribute='status') \ No newline at end of file diff --git a/molecule/organization/converge.yml b/molecule/organization/converge.yml deleted file mode 100644 index 95aa102..0000000 --- a/molecule/organization/converge.yml +++ /dev/null @@ -1,28 +0,0 @@ ---- -- name: Install - user: ansible - hosts: all - become: yes - vars: - - runner_user: ansible - - github_account: monolithprojects-testorg - - runner_org: yes - - runner_state: "stopped" - - runner_version: "2.274.2" - roles: - - robertdebock.epel - - ansible-github_actions_runner - -- name: Reinstall - user: ansible - hosts: all - become: yes - vars: - - runner_user: ansible - - github_account: monolithprojects-testorg - - runner_org: yes - - reinstall_runner: yes - - runner_version: "latest" - roles: - - robertdebock.epel - - ansible-github_actions_runner \ No newline at end of file diff --git a/molecule/organization/molecule.yml b/molecule/organization/molecule.yml deleted file mode 100644 index df31db3..0000000 --- a/molecule/organization/molecule.yml +++ /dev/null @@ -1,124 +0,0 @@ ---- -driver: - name: docker -lint: | - yamllint . - ansible-lint -platforms: - - name: CentOS7 - image: monolithprojects/systemd-centos7:latest - command: /sbin/init - tmpfs: - - /run - - /tmp - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: yes - pre_build_image: yes - - name: CentOS8 - image: monolithprojects/systemd-centos8:latest - command: /sbin/init - tmpfs: - - /run - - /tmp - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: yes - pre_build_image: yes - - name: Fedora32 - image: monolithprojects/systemd-fedora32:latest - command: /sbin/init - tmpfs: - - /run - - /tmp - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: yes - pre_build_image: yes - - name: Fedora33 - image: monolithprojects/systemd-fedora33:latest - command: /sbin/init - tmpfs: - - /run - - /tmp - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: yes - pre_build_image: yes - - name: Ubuntu16 - image: monolithprojects/systemd-ubuntu16:latest - command: /sbin/init - tmpfs: - - /run - - /tmp - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: yes - pre_build_image: yes - - name: Ubuntu18 - image: monolithprojects/systemd-ubuntu18:latest - command: /sbin/init - tmpfs: - - /run - - /tmp - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: yes - pre_build_image: yes - - name: Ubuntu20 - image: monolithprojects/systemd-ubuntu20:latest - command: /sbin/init - tmpfs: - - /run - - /tmp - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: yes - pre_build_image: yes - - name: Debian9 - image: monolithprojects/systemd-debian9:latest - command: /sbin/init - tmpfs: - - /run - - /tmp - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: yes - pre_build_image: yes - - name: Debian10 - image: monolithprojects/systemd-debian10:latest - command: /sbin/init - tmpfs: - - /run - - /tmp - volumes: - - /sys/fs/cgroup:/sys/fs/cgroup:ro - privileged: yes - pre_build_image: yes -provisioner: - name: ansible - playbooks: - converge: converge.yml - cleanup: cleanup.yml - log: false -verifier: - name: testinfra - directory: tests -dependency: - name: galaxy - options: - ignore-certs: True - ignore-errors: True -scenario: - name: organization - test_sequence: - - dependency - - lint - - destroy - - syntax - - create - # - prepare - - converge - # - idempotence - - cleanup - - destroy \ No newline at end of file diff --git a/molecule/organization/tests/test_default.py b/molecule/organization/tests/test_default.py deleted file mode 100644 index c62900f..0000000 --- a/molecule/organization/tests/test_default.py +++ /dev/null @@ -1,13 +0,0 @@ -import os - -import testinfra.utils.ansible_runner - -testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ['MOLECULE_INVENTORY_FILE'] -).get_hosts('all') - - -def test_hosts_file(host): - f = host.file('/opt/actions-runner') - - assert f.exists \ No newline at end of file diff --git a/molecule/organization/verify.yml b/molecule/organization/verify.yml deleted file mode 100644 index 79044cd..0000000 --- a/molecule/organization/verify.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -# This is an example playbook to execute Ansible tests. - -- name: Verify - hosts: all - gather_facts: false - tasks: - - name: Example assertion - assert: - that: true diff --git a/molecule/repo/cleanup.yml b/molecule/repo/cleanup.yml new file mode 100644 index 0000000..d42361e --- /dev/null +++ b/molecule/repo/cleanup.yml @@ -0,0 +1,12 @@ +--- +- name: Cleanup + user: ansible + hosts: all + become: yes + vars: + - runner_user: ansible + - github_repo: ansible-github_actions_runner-testrepo + - github_account: monolithprojects + - runner_state: absent + roles: + - ansible-github_actions_runner \ No newline at end of file diff --git a/molecule/repo/converge.yml b/molecule/repo/converge.yml new file mode 100644 index 0000000..77c772d --- /dev/null +++ b/molecule/repo/converge.yml @@ -0,0 +1,15 @@ +--- +- name: Install Repo runner + user: ansible + hosts: all + 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: "'test1','repo-runner'" + roles: + - robertdebock.epel + - ansible-github_actions_runner \ No newline at end of file diff --git a/molecule/repo/molecule.yml b/molecule/repo/molecule.yml new file mode 100644 index 0000000..bd19f00 --- /dev/null +++ b/molecule/repo/molecule.yml @@ -0,0 +1,40 @@ +--- +provisioner: + name: ansible + playbooks: + converge: converge.yml + cleanup: cleanup.yml + verify: verify.yml +dependency: + name: galaxy +lint: | + yamllint . + ansible-lint . +driver: + name: docker +platforms: + - name: "${os:-ubuntu16}-${tag:-latest}" + image: "${namespace:-monolithprojects}/systemd-${os:-ubuntu16}:${tag:-latest}" + command: /sbin/init + tmpfs: + - /run + - /tmp + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: yes + pre_build_image: yes +verifier: + name: ansible +scenario: + name: repo + test_sequence: + - dependency + - lint + - destroy + - syntax + - create + - converge + - idempotence + - verify + - cleanup + - destroy \ No newline at end of file diff --git a/molecule/repo/requirements.yml b/molecule/repo/requirements.yml new file mode 100644 index 0000000..9768a73 --- /dev/null +++ b/molecule/repo/requirements.yml @@ -0,0 +1,3 @@ +--- +- role: robertdebock.epel + version: 3.0.1 diff --git a/molecule/repo/verify.yml b/molecule/repo/verify.yml new file mode 100644 index 0000000..b172cd2 --- /dev/null +++ b/molecule/repo/verify.yml @@ -0,0 +1,41 @@ +--- +- 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: "{{ ansible_hostname }}" + + tasks: + - name: Give the runners some time + pause: + seconds: 30 + + - name: Check currently registered runners + uri: + url: "{{ github_api_url }}/repos/{{ github_owner | default(github_account) }}/{{ github_repo }}/actions/runners" + headers: + Authorization: "token {{ access_token }}" + Accept: "application/vnd.github.v3+json" + method: GET + status_code: 200 + force_basic_auth: yes + register: registered_runners + + - debug: + var: registered_runners.json.runners|map(attribute='status') + + - name: Check Runner + assert: + that: + - runner_name in registered_runners.json.runners|map(attribute='name')|list + quiet: true + + - debug: + var: registered_runners.json.runners|map(attribute='name') diff --git a/tasks/collect_info_org.yml b/tasks/collect_info_org.yml index 1eaac2f..7267b88 100644 --- a/tasks/collect_info_org.yml +++ b/tasks/collect_info_org.yml @@ -37,7 +37,7 @@ - name: Build service name set_fact: - runner_service: "actions.runner.{{ (github_owner | default(github_account))[:45] }}.{{ runner_name }}.service" + runner_service: "actions.runner.{{ ([( github_owner | default(github_account))[:45], runner_name] | join('.'))[:57] }}.service" when: service_name is not defined tags: - install diff --git a/tasks/collect_info_repo.yml b/tasks/collect_info_repo.yml index 15bb06e..d021ada 100644 --- a/tasks/collect_info_repo.yml +++ b/tasks/collect_info_repo.yml @@ -35,16 +35,9 @@ - install - uninstall -- name: Combine Github account and repo names - set_fact: - svc_name: "{{ github_owner | default(github_account) }}-{{ github_repo }}" - tags: - - install - - uninstall - - name: Build service name set_fact: - runner_service: "actions.runner.{{ svc_name[:45] }}.{{ runner_name }}.service" + runner_service: "actions.runner.{{ ([([(github_owner | default(github_account)), github_repo ] | join('-'))[:45], runner_name] | join('.'))[:57] }}.service" when: service_name is not defined tags: - install diff --git a/tasks/install_runner.yml b/tasks/install_runner.yml index f59efe2..352486c 100644 --- a/tasks/install_runner.yml +++ b/tasks/install_runner.yml @@ -3,10 +3,9 @@ file: path: "{{ runner_dir }}" state: directory - mode: "0755" + mode: 0755 owner: "{{ runner_user }}" - group: "{{ runner_user }}" - recurse: yes + # group: "{{ runner_user }}" tags: - install @@ -45,7 +44,7 @@ path: "{{ runner_pkg_tempdir }}" state: directory recurse: yes - mode: '0777' + mode: 0777 run_once: yes delegate_to: localhost become: false @@ -73,8 +72,6 @@ owner: "{{ runner_user }}" mode: 0755 when: runner_version not in runner_installed.stdout or reinstall_runner - notify: - - Restart runner service tags: - install @@ -134,7 +131,7 @@ tags: - install -- name: Enable and START Github Actions Runner service +- name: START and enable Github Actions Runner service systemd: name: "{{ runner_service }}" state: started @@ -143,11 +140,11 @@ tags: - install -- name: Enable and STOP Github Actions Runner service +- name: STOP and disable Github Actions Runner service systemd: name: "{{ runner_service }}" state: stopped - enabled: yes + enabled: no when: runner_state|lower == "stopped" tags: - install diff --git a/tasks/uninstall_runner.yml b/tasks/uninstall_runner.yml index 36319b4..b2af08e 100644 --- a/tasks/uninstall_runner.yml +++ b/tasks/uninstall_runner.yml @@ -4,7 +4,7 @@ name: "{{ runner_service }}" state: stopped enabled: no - when: runner_service in services + when: runner_service in services and ( reinstall_runner or runner_state == "stopped" or runner_state == "absent" ) tags: - uninstall @@ -43,7 +43,7 @@ become: yes become_user: "{{ runner_user }}" no_log: "{{ hide_sensitive_logs | bool }}" - when: ansible_hostname in registered_runners.json.runners|map(attribute='name')|list and runner_file.stat.exists + when: runner_name in registered_runners.json.runners|map(attribute='name')|list and runner_file.stat.exists tags: - uninstall