@ -9,6 +9,7 @@ Enables Continuous Delivery with Red Hat 3scale API Management Platform (3scale
## Requirements
## Requirements
This role requires:
This role requires:
- an instance of 3scale API Management Platform (hosted or on-premise)
- an instance of 3scale API Management Platform (hosted or on-premise)
- an instance of Red Hat SSO if you plan to use OpenID Connect authentication
- an instance of Red Hat SSO if you plan to use OpenID Connect authentication
- two APIcast gateways (staging and production), either hosted or self-managed
- two APIcast gateways (staging and production), either hosted or self-managed
@ -18,12 +19,14 @@ All the components are driven through APIs, so no SSH connection is required!
On the control node, the `jmespath` library is required. If it is not already there,
On the control node, the `jmespath` library is required. If it is not already there,
you can install it with:
you can install it with:
```
```sh
pip install jmespath
pip install jmespath
```
```
A recent version of Jinja (2.8) is also required. You can upgrade your Jinja version with:
A recent version of Jinja (2.8) is also required. You can upgrade your Jinja version with:
```
```sh
pip install -U Jinja2
pip install -U Jinja2
```
```
@ -35,13 +38,15 @@ to install the missing dependencies.
If you want to deploy the classic "Echo API" on a SaaS 3scale instance using API Keys,
If you want to deploy the classic "Echo API" on a SaaS 3scale instance using API Keys,
you can do it in three steps:
you can do it in three steps:
1. Craft a Swagger file for your Echo API
1. Craft a Swagger file for your Echo API
2. Build your inventory file
2. Build your inventory file
3. Write the playbook
3. Write the playbook
4. Run the playbook!
4. Run the playbook!
First, make sure your swagger file (`api-swagger.yaml`) has the required information:
First, make sure your swagger file (`api-swagger.yaml`) has the required information:
```
```yaml
swagger: '2.0'
swagger: '2.0'
info:
info:
x-threescale-system-name: 'echo-api'
x-threescale-system-name: 'echo-api'
@ -68,6 +73,7 @@ securityDefinitions:
```
```
In this Swagger file, the following fields are used:
In this Swagger file, the following fields are used:
- `x-threescale-system-name` is used as system_name for the configuration objects in 3scale.
- `x-threescale-system-name` is used as system_name for the configuration objects in 3scale.
- `title` is used as the name of the service definition.
- `title` is used as the name of the service definition.
- `version` is used for proper versioning and follows the [semver scheme](https://semver.org/).
- `version` is used for proper versioning and follows the [semver scheme](https://semver.org/).
@ -78,7 +84,8 @@ In this Swagger file, the following fields are used:
- the `security` and `securityDefinitions` are used to determine the security scheme of the exposed API. In this example, we are using the API Keys scheme.
- the `security` and `securityDefinitions` are used to determine the security scheme of the exposed API. In this example, we are using the API Keys scheme.
- the 3scale admin portal needs to be declared in a group named `threescale`.
- the 3scale admin portal needs to be declared in a group named `threescale`.
- the [3scale access token](https://access.redhat.com/documentation/en-us/red_hat_3scale/2.saas/html-single/accounts/index#access_tokens) needs to be set in the `threescale_cicd_access_token` variable.
- the [3scale access token](https://access.redhat.com/documentation/en-us/red_hat_3scale/2.saas/html-single/accounts/index#access_tokens) needs to be set in the `threescale_cicd_access_token` variable.
- since no SSH connection is needed (we only use the 3scale Admin APIs), `ansible_connection=local` is set to the whole inventory.
- since no SSH connection is needed (we only use the 3scale Admin APIs), `ansible_connection=local` is set to the whole inventory.
You can now write the playbook (`deploy-api.yaml`):
You can now write the playbook (`deploy-api.yaml`):
```
```yaml
- hosts: threescale
- hosts: threescale
gather_facts: no
gather_facts: no
vars:
vars:
@ -105,23 +114,438 @@ You can now write the playbook (`deploy-api.yaml`):
```
```
The main parts are:
The main parts are:
- `threescale_cicd_openapi_file` is the path to the swagger file defined in step 1.
- `threescale_cicd_openapi_file` is the path to the swagger file defined in step 1.
- the `nmasse-itix.threescale-cicd` role is used.
- the `nmasse-itix.threescale-cicd` role is used.
- `gather_facts: no` needs to be used since there is no SSH connection to the target systems.
- `gather_facts: no` needs to be used since there is no SSH connection to the target systems.
- **Default value:** none, no prefixing is performed.
- **Examples:**`dev`, `test` or `prod`
### Miscellaneous variables
Miscellaneous variables defined in [defaults/main.yml](defaults/main.yml])
provide sensible defaults. Have a look at them.
## Dependencies
## Dependencies
This role has no dependencies.
This role has no dependencies on other roles, but it has dependencies on:
- Ansible (at least version 2.4)
- JMESPath
- Jinja (at least version 2.8)
## Usage in Ansible Tower
If you want to use this role in Ansible Tower, the easiest way to do so is:
- to have an inventory for each of your environments (dev, test, prod, etc.)
- in those inventories, define a group (let's say `threescale`) containing
the 3scale Admin Portal(s) of this environment
- set all the variables that depends on the environment (`threescale_cicd_wildcard_domain`, `threescale_cicd_api_environment_name`, etc.) as
group variables
- create a playbook, committed in your GIT repository and reference it as a Project
in Tower
- in this playbook, use the `assert` module to do some surface checks and set the variables that depends on the API being provisioned (such as `threescale_cicd_private_base_url`)
- create the corresponding Job Template
A very minimalistic playbook could be:
```yaml
---
- name: Deploy an API on a 3scale instance
hosts: threescale
gather_facts: no
pre_tasks:
- assert:
that:
- "git_repo is defined"
- name: Clone the git repo containing the API Definition
- name:Compute the system_name prefix to prepend to the generated system_name
- name:Compute the system_name prefix to prepend to the generated system_name
set_fact:
set_fact:
threescale_cicd_api_system_name_prefix:'{{ (threescale_cicd_api_system_name is not defined and threescale_cicd_env is defined)|ternary((threescale_cicd_env|default("")|regex_replace(''[^a-zA-Z0-9_]+'', ''_'')) ~ "_", "") }}'
threescale_cicd_api_system_name_prefix:'{{ (threescale_cicd_api_system_name is not defined and threescale_cicd_api_environment_name is defined)|ternary((threescale_cicd_api_environment_name|default("")|regex_replace(''[^a-zA-Z0-9_]+'', ''_'')) ~ "_", "") }}'
- name:Extract the wanted system_name from OpenAPI
- name:Extract the wanted system_name from OpenAPI