Injection des variables d'env du conteneur.

This commit is contained in:
William 2022-07-01 21:46:39 +02:00
parent 4528c5daf4
commit 6c85124ea5
5 changed files with 30 additions and 8 deletions

3
.env.j2 Normal file
View File

@ -0,0 +1,3 @@
{% for key,value in envvars.items() %}
{{ key }}={{ value }}
{% endfor %}

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/playbook.retry
/hosts.ini
/vars.json

View File

@ -4,19 +4,30 @@ This playbook installs app from repository and bind Traefik on defined host.
## Installing
Copy then change values of hosts example file:
Copy then change values of hosts example file :
```bash
$ cp hosts.example.ini hosts.ini
```
Then create a file `vars.json` vars who contain :
```json
{
"name": "myapp",
"repository": "https://git.example.com/vendor/app.git",
"version": "master",
"host": "myapp.example.com",
"dockerfile": "Dockerfile",
"envvars": {
"APP_NAME": "Wonderful",
"APP_ENV": "production"
}
}
```
Then run the playbook:
```bash
$ ansible-playbook -i hosts.ini playbook.yml \
-e name=myapp \
-e repository=https://git.example.com/vendor/app.git \
-e version=master \
-e host=myapp.example.com
-e dockerfile=Dockerfile
$ ansible-playbook -i hosts.ini playbook.yml -e @vars.json
```

View File

@ -9,6 +9,8 @@ services:
build:
context: ./
dockerfile: {{ dockerfile }}
env_file:
- .env.pilot
networks:
- web
labels:

View File

@ -10,6 +10,11 @@
dest: "{{ working_dir }}/{{ name }}"
version: "{{ version }}"
- name: Build env file
template:
src: .env.j2
dest: '{{ working_dir }}/{{ name }}/.env.pilot'
- name: Build docker-compose file
template:
src: docker-compose.yml.j2