diff --git a/.env.j2 b/.env.j2 new file mode 100644 index 0000000..62baa88 --- /dev/null +++ b/.env.j2 @@ -0,0 +1,3 @@ +{% for key,value in envvars.items() %} +{{ key }}={{ value }} +{% endfor %} diff --git a/.gitignore b/.gitignore index a80359c..aa2c66c 100755 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /playbook.retry /hosts.ini +/vars.json diff --git a/README.md b/README.md index b21f930..6a3865e 100644 --- a/README.md +++ b/README.md @@ -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 run the playbook: +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 ``` diff --git a/docker-compose.yml.j2 b/docker-compose.yml.j2 index 30cf048..d8f67ed 100644 --- a/docker-compose.yml.j2 +++ b/docker-compose.yml.j2 @@ -9,6 +9,8 @@ services: build: context: ./ dockerfile: {{ dockerfile }} + env_file: + - .env.pilot networks: - web labels: diff --git a/playbook.yml b/playbook.yml index 8b75e4b..cb488b6 100755 --- a/playbook.yml +++ b/playbook.yml @@ -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