Skip to content

Commit

Permalink
chore: fix GitHub actions and run it regularly (#20)
Browse files Browse the repository at this point in the history
* chore: update to fedora40 and Ubuntu24.04
* fix: install python3-docker through apt
* doc: mention `act` to run GitHub Actions locally
* feat: python venv for testing locally
  • Loading branch information
DrPsychick authored Jul 6, 2024
1 parent 3e3e4e0 commit 2b12b90
Showing 17 changed files with 80 additions and 31 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ jobs:
- name: Test
uses: gofrolist/molecule-action@v2
with:
# molecule_options: --debug -v
molecule_working_dir: "${{ github.repository }}"
molecule_command: test
env:
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/.venv
/ansible.cfg
31 changes: 24 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -30,9 +30,10 @@ If you have other systems you want to test, feel free to provide a PR with addit

Contributing is really easy:
1. Fork the project on GitHub : https://github.com/DrPsychick/ansible-testing
2. Checkout the fork on your Linux box
3. Symlink the fork in your roles Molecule scenario (i.e. `./molecule/default/`)
4. Make changes and test your role with them until you're happy - commit and create a pull-request
1. Checkout the fork on your Linux box
1. Symlink the fork in your roles Molecule scenario (i.e. `./molecule/default/`)
1. Make changes and test your role with them until you're happy - commit and create a pull-request
1. You can run GitHub Actions locally for fast feedback with `act`: https://nektosact.com/installation/index.html

```shell
GitHubName=YourName
@@ -86,17 +87,17 @@ Then adjust the `platforms` in `molecule/default/molecule.yml` accordingly.
```yaml
work_dir: "/tmp/ansible-testrole-default"
containers:
- { name: fedora38, os: fedora, dockerfile: Dockerfile_Fedora, files: ["entrypoint.sh"], args: { VERSION: 38 } }
- { name: ubuntu2204, os: ubuntu, dockerfile: Dockerfile_Ubuntu, files: ["entrypoint.sh"], args: { VERSION: 22.04 } }
- { name: fedora40, os: fedora, dockerfile: Dockerfile_Fedora, files: ["entrypoint.sh"], args: { VERSION: 40 } }
- { name: ubuntu2404, os: ubuntu, dockerfile: Dockerfile_Ubuntu, files: ["entrypoint.sh"], args: { VERSION: 24.04 } }
- { name: centos7, os: centos, dockerfile: Dockerfile_CentOS, files: ["entrypoint.sh"], args: { VERSION: 7 } }
```
`molecule.yml`
```yaml
[...]
platforms:
- name: fedora38
- name: ubuntu2204
- name: fedora40
- name: ubuntu2404
- name: centos7
[...]
```
@@ -209,3 +210,19 @@ A full spin-up (create) run for 2 Windows instances with predefined images took
2. Create a zip from the ready to use VM: `zip windows2016-clean.qcow2.zip windows2016.qcow2`
(the filename must match and be in the root of the zip file - with no path)
3. Move the zip file to `libvirt_iso_dir` or provide it via URL (`disk_image_url`)

# Test locally with different Ansible versions

Requires `python3-venv`

```shell
# version 16 and latest fail with
# ERROR! Unexpected Exception, this is probably a bug: cannot import name 'should_retry_error' from 'ansible.galaxy.api'
ANSIBLE_VERSION=15
python3 -m venv .venv
. .venv/bin/activate
pip3 install --upgrade pip setuptools wheel
pip3 install --requirement requirements-ansible_${ANSIBLE_VERSION}.txt
molecule test
```
4 changes: 2 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -5,9 +5,9 @@ ssh_keyname: "ansible@local"
# defining the containers you want to create
containers: []
# - { name: fedora33, os: fedora, dockerfile: Dockerfile_Fedora, files: ["entrypoint.sh"], args: { VERSION: 33 } }
# - { name: fedora38, os: fedora, dockerfile: Dockerfile_Fedora, files: ["entrypoint.sh"], args: { VERSION: 38 } }
# - { name: fedora40, os: fedora, dockerfile: Dockerfile_Fedora, files: ["entrypoint.sh"], args: { VERSION: 40 } }
# - { name: ubuntu2004, os: ubuntu, dockerfile: Dockerfile_Ubuntu, files: ["entrypoint.sh"], args: { VERSION: 20.04 } }
# - { name: ubuntu2204, os: ubuntu, dockerfile: Dockerfile_Ubuntu, files: ["entrypoint.sh"], args: { VERSION: 22.04 } }
# - { name: ubuntu2404, os: ubuntu, dockerfile: Dockerfile_Ubuntu, files: ["entrypoint.sh"], args: { VERSION: 24.04 } }
# - { name: centos7, os: centos, dockerfile: Dockerfile_CentOS, files: ["entrypoint.sh"], args: { VERSION: 7 } }
# - { name: centos8, os: centos, dockerfile: Dockerfile_CentOS, files: ["entrypoint.sh"], args: { VERSION: 8 } }

4 changes: 2 additions & 2 deletions docs/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ dependency:
driver:
name: docker
platforms:
- name: fedora38
- name: ubuntu2204
- name: fedora40
- name: ubuntu2404
- name: centos8
provisioner:
name: ansible
4 changes: 2 additions & 2 deletions docs/molecule/default/vars.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
work_dir: "/tmp/ansible-testhost"
containers:
# - { name: fedora33, os: fedora, dockerfile: Dockerfile_Fedora, files: ["entrypoint.sh"], args: { VERSION: 33 } }
- { name: fedora38, os: fedora, dockerfile: Dockerfile_Fedora, files: ["entrypoint.sh"], args: { VERSION: 38 } }
- { name: fedora40, os: fedora, dockerfile: Dockerfile_Fedora, files: ["entrypoint.sh"], args: { VERSION: 40 } }
# - { name: ubuntu2004, os: ubuntu, dockerfile: Dockerfile_Ubuntu, files: ["entrypoint.sh"], args: { VERSION: 20.04 } }
- { name: ubuntu2204, os: ubuntu, dockerfile: Dockerfile_Ubuntu, files: ["entrypoint.sh"], args: { VERSION: 22.04 } }
- { name: ubuntu2404, os: ubuntu, dockerfile: Dockerfile_Ubuntu, files: ["entrypoint.sh"], args: { VERSION: 24.04 } }
# - { name: centos7, os: centos, dockerfile: Dockerfile_CentOS, files: ["entrypoint.sh"], args: { VERSION: 7 } }
- { name: centos8, os: centos, dockerfile: Dockerfile_CentOS, files: ["entrypoint.sh"], args: { VERSION: 8 } }
2 changes: 1 addition & 1 deletion files/docker/Dockerfile_Fedora
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG VERSION=38
ARG VERSION=40
FROM fedora:$VERSION

ENV container=docker
2 changes: 1 addition & 1 deletion files/docker/Dockerfile_Ubuntu
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG VERSION=22.04
ARG VERSION=24.04
FROM ubuntu:$VERSION

ENV container=docker
8 changes: 4 additions & 4 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ galaxy_info:
- libvirt
- molecule

dependencies:
- community.docker
- community.general
- community.libvirt
dependencies:
"community.docker": ">=3.10.0"
"community.general": ">=9.0.0"
"community.libvirt": ">=1.3.0"
4 changes: 2 additions & 2 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@ driver:
lint: |
ansible-lint
platforms:
- name: ubuntu2204
- name: fedora38
- name: ubuntu2404
- name: fedora40
# - name: debian11
provisioner:
name: ansible
7 changes: 1 addition & 6 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
@@ -23,9 +23,4 @@
tasks:
- name: Required packages
ansible.builtin.package:
name: "{{ ['python3-setuptools', 'python3-pip'] + (['openssh-client'] if ansible_distribution in ['Ubuntu','Debian'] else ['openssh-clients']) }}"

- name: Required pip packages
ansible.builtin.pip:
name: ["docker"]
state: latest
name: "{{ ['python3-setuptools', 'python3-pip', 'python3-docker'] + (['openssh-client'] if ansible_distribution in ['Ubuntu','Debian'] else ['openssh-clients']) }}"
4 changes: 2 additions & 2 deletions molecule/default/vars.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
work_dir: "/tmp/ansible-drpsychick.ansible_testing-default"
containers:
- { name: ubuntu2204, os: ubuntu, dockerfile: Dockerfile_Ubuntu, files: ["entrypoint.sh"], args: { VERSION: 22.04 } }
- { name: fedora38, os: fedora, dockerfile: Dockerfile_Fedora, files: ["entrypoint.sh"], args: { VERSION: 38 } }
- { name: ubuntu2404, os: ubuntu, dockerfile: Dockerfile_Ubuntu, files: ["entrypoint.sh"], args: { VERSION: 24.04 } }
- { name: fedora40, os: fedora, dockerfile: Dockerfile_Fedora, files: ["entrypoint.sh"], args: { VERSION: 40 } }
# - { name: debian11, os: ubuntu, dockerfile: Dockerfile_Debian, files: ["entrypoint.sh"], args: { VERSION: 11 } }
virtual_machines: []
9 changes: 9 additions & 0 deletions requirements-ansible_14.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# includes ansible-core 2.14.x
ansible<8.0.0
ansible-base
ansible-lint
ansible-lint-junit
ansible-compat
pywinrm
molecule
molecule-docker
9 changes: 9 additions & 0 deletions requirements-ansible_15.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# includes ansible-core 2.15.x
ansible<9.0.0
ansible-base
ansible-lint
ansible-lint-junit
ansible-compat
pywinrm
molecule
molecule-docker
9 changes: 9 additions & 0 deletions requirements-ansible_16.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# includes ansible-core 2.16.x
ansible<10.0.0
ansible-base
ansible-lint
ansible-lint-junit
ansible-compat
pywinrm
molecule
molecule-docker
8 changes: 8 additions & 0 deletions requirements-ansible_latest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ansible
ansible-base
ansible-lint
ansible-lint-junit
ansible-compat
pywinrm
molecule
molecule-docker
4 changes: 2 additions & 2 deletions tests/provision.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
containers:
# - { name: fedora33, os: fedora, dockerfile: Dockerfile_Fedora, files: ["entrypoint.sh"], args: { VERSION: 33 } }
# - { name: fedora38, os: fedora, dockerfile: Dockerfile_Fedora, files: ["entrypoint.sh"], args: { VERSION: 38 } }
# - { name: fedora40, os: fedora, dockerfile: Dockerfile_Fedora, files: ["entrypoint.sh"], args: { VERSION: 40 } }
- { name: ubuntu2004, os: ubuntu, dockerfile: Dockerfile_Ubuntu, files: ["entrypoint.sh"], args: { VERSION: 20.04 } }
# - { name: ubuntu2204, os: ubuntu, dockerfile: Dockerfile_Ubuntu, files: ["entrypoint.sh"], args: { VERSION: 22.04 } }
# - { name: ubuntu2404, os: ubuntu, dockerfile: Dockerfile_Ubuntu, files: ["entrypoint.sh"], args: { VERSION: 24.04 } }
# - { name: centos7, os: centos, dockerfile: Dockerfile_CentOS, files: ["entrypoint.sh"], args: { VERSION: 7 } }
# - { name: centos8, os: centos, dockerfile: Dockerfile_CentOS, files: ["entrypoint.sh"], args: { VERSION: 8 } }

0 comments on commit 2b12b90

Please sign in to comment.