Skip to main content

Review Ansible

Creates and removes a GitLab review environment with project-owned Ansible playbooks.

The component runs both playbooks in the CI Tools Ansible execution-environment image, initializes SSH through ci_ssh_init, and serializes start and stop operations with a resource group.

Basic review environment​

Keep the inventory and playbooks in the application repository:

# playbooks/start-review.yml
---
- name: Deploy review application
hosts: review
become: true
tasks:
- name: Start the application
ansible.builtin.service:
name: my-application
state: started
# playbooks/stop-review.yml
---
- name: Remove review application
hosts: review
become: true
tasks:
- name: Stop the application
ansible.builtin.service:
name: my-application
state: stopped

Include the component and point it at the inventory and playbooks:

include:
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/ansible-molecule@$CI_COMMIT_SHA
inputs:
name: review
- component: $CI_SERVER_FQDN/xrow-public/ci-tools/review-ansible@$CI_COMMIT_SHA
inputs:
name: review
environment: review/$CI_COMMIT_REF_SLUG
inventory: inventories/review
review-domain: $CI_ENVIRONMENT_SLUG.apps.example.com
start-playbook: playbooks/start-review.yml
stop-playbook: playbooks/stop-review.yml
needs-start:
- job: molecule:review
artifacts: false

This creates molecule:review, review:start, and review:stop. The review environment starts only after the Molecule scenarios pass. The start job exposes the environment at https://$CI_ENVIRONMENT_HOST; the stop job is registered as its GitLab on_stop action. Branch and merge-request pipelines run the jobs when their corresponding playbooks exist. Tag pipelines expose the jobs as manual actions when the start playbook exists, while scheduled pipelines skip them.

CI prerequisites​

The selected runner must be able to reach the inventory hosts. Configure the SSH key and host verification values expected by ci_ssh_init as protected or masked CI/CD variables, and keep secrets out of the inventory committed to the repository.

The start playbook should:

  • create or update only the resources owned by the review environment;
  • be idempotent so a retried job converges safely;
  • fail when the environment cannot be made ready.

The stop playbook should:

  • remove the same resources created by the start playbook;
  • tolerate resources that have already been removed;
  • avoid deleting shared infrastructure.

Environment lifecycle​

environment names the GitLab environment and its resource group. review-domain sets CI_ENVIRONMENT_HOST and therefore the environment URL. timeout controls both the start-job timeout and GitLab's automatic stop interval.

Use needs-start for quality gates such as molecule:review that must pass before provisioning. Use needs-stop for the final review test that must complete before the environment stops. Set tag when the Ansible jobs require a tagged runner.

Inputs​

NameDescriptionDefaultType
------------
environmentGitLab environment prefix.intstring
inventoryInventory file for the review environment.string
nameName of the review job. Used to name the start and stop jobs.reviewstring
needs-startThe jobs that the start job depends on.[]array
needs-stopThe jobs that the stop job depends on.[]array
review-domain$CI_ENVIRONMENT_SLUG.review.xrow.netstring
rulesThe rules to determine when to run the review process.[{"if":"$CI_PIPELINE_SOURCE == \"schedule\"","when":"never"},{"if":"$CI_COMMIT_TAG =~ $CI_PATTERN_SEMVER","when":"never"},{"when":"always"}]array
stageteststring
start-playbookPlaybook for starting the reviewplaybooks/start-review.ymlstring
stop-playbookPlaybook for stopping the reviewplaybooks/stop-review.ymlstring
tagstring
timeout1hstring