semaphoreui / semaphore

Modern UI and powerful API for Ansible, Terraform, OpenTofu, PowerShell and other DevOps tools.
https://semaphoreui.com
MIT License
10.55k stars 1.06k forks source link

Feature: Ansible Testing with Molecule and Linting #1377

Open ansibleguy opened 1 year ago

ansibleguy commented 1 year ago

Greetings!

Semaphore could use an integration for Ansible-based test-suites like:

Why?

Such test-suites are used to build and maintain a healthy Ansible configuration (Playbooks, Roles, Tasks, Modules, Vars, ...). In my eyes this functionality would enhance Semaphore as it lowers the dependency on other CI/CD platforms. A scheduled execution of Ansible-Molecule tests would very nice to have.

How?

These are some ideas I had: (might be flawed and have much potential for improvements)

Basically:

From the frontend perspective:

From the backend perspective:

When to run?

  1. Before task execution

    Prepare repository (clone if needed) => run tests => execute

    Especially for linting tests, that don't take a lot of time to finish, it makes sense to execute them before executing a 'task'.

  2. Scheduled

    Tests for Molecule easily take 5+ minutes to finish. Most people would not want to run these test before every 'task' execution as the overhead is too much. Especially for Molecule tests it would be good to be able to schedule them using cron.

Contribution

I could give the backend implementation(s) a try - after the basics are defined.

ansibleguy commented 1 year ago

Addition: Molecule cleanup should also be handled by lib/AnsibleMolecule.go Example written in bash that should be executed before every test:

function cleanup {
  if [ -d "$PATH_TEST_FULL" ]
  then
    if [[ "$status" != "PASSED" ]]
    then
      cd "$PATH_TEST_FULL"
      molecule destroy
    fi
    cd /tmp
    rm -rf "$PATH_TEST_FULL"
  fi
  rm -rf "$HOME/.cache/molecule/$ROLE"
  if [ -d "$HOME/.cache/ansible-compat" ]
  then
    find "$HOME/.cache/ansible-compat" -maxdepth 0 -type d -mmin +30 -exec rm -rf {} \;
  fi
}

Note: mmin +30 => 30min could be not enough time for some tests to finish Reference to a full bash-script: molecule.sh.j2