This project implements a Gitlab CI template for [Ansible](https://www.ansible.com/).
## Overview
This template implements continuous delivery/continuous deployment for projects that deploy their environments with Ansible.
## Overview: managed environments
It provides several features, usable in different modes.
This template implements Ansible-based deployments.
It allows you to manage automatic deployment & cleanup of standard predefined environments.
Each environment can be enabled/disabled by configuration.
If you're not satisfied with predefined environments and/or their associated Git workflow, you may implement you own environments and
workflow, by reusing/extending the base (hidden) jobs. This is advanced usage and will not be covered by this documentation.
The following chapters present the managed predefined environments and their associated Git workflow.
### Review environments
@@ -30,7 +36,7 @@ It is only active for your integration branch (`develop` by default).
### Production environments
Lastly, the template supports 2 environments associated to your production branch (`master` by default):
Lastly, the template supports 2 environments associated to your production branch (`master`or `main`by default):
* a **staging** environment (an iso-prod environment meant for testing and validation purpose),
* the **production** environment.
@@ -216,6 +222,32 @@ Deployment jobs also support _optional_ **hook scripts** from your project, loca
*`pre-ansible-playbook.sh` is executed **before** running `ansible-playbook`, to perform specific environment pre-initialization such as generating a dynamic inventory
*`post-ansible-playbook.sh` is executed **after** running `ansible-playbook`, to perform specific environment post-initialization
#### Static vs. Dynamic environment URLs
The Ansible template supports two ways of defining your environments url:
* a **static way**: when you know your environments url in advance, probably because you're exposing your routes through a DNS you manage,
* a [**dynamic way**](https://docs.gitlab.com/ee/ci/environments/#set-dynamic-environment-urls-after-a-job-finishes): when the url cannot be known before the
deployment job is executed.
The static way can be implemented simply by setting the overridding the [`environment:url`](https://docs.gitlab.com/ee/ci/yaml/#environmenturl) attribute in each
deployment job.
Example:
```yaml
ansible-staging:
environment:
url:"https://myapp-staging.noprod.domain"
ansible-production:
environment:
url:"https://myapp.prod.domain"
```
To implement the dynamic way, your post deployment hook script shall simply generate a `environment_url.txt` file, containing only
the dynamically generated url. This will be considered by the template as the newly deployed environment url.
### Ansible lint job
The Ansible template enables [Ansible Lint](https://docs.ansible.com/ansible-lint/) analysis of your Ansible scripts.