mirror of
https://github.com/2martens/cloud-configuration.git
synced 2026-10-17 16:46:51 +02:00
Added kafka and springBoot roles, minor cleanup, and use ansible-vault to hide sensitive data
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
dependencies:
|
||||
- role: docker
|
||||
- role: letsencrypt
|
||||
- role: nginx
|
||||
- role: kafka
|
||||
@@ -0,0 +1,19 @@
|
||||
---
|
||||
- name: Create Spring Boot application directory
|
||||
ansible.builtin.file:
|
||||
state: directory
|
||||
path: /opt/{{ spring_docker_path }}
|
||||
owner: root
|
||||
group: root
|
||||
mode: "755"
|
||||
- name: Copy docker compose file for application
|
||||
ansible.builtin.template:
|
||||
src: opt/application/docker-compose.yaml.j2
|
||||
dest: /opt/{{ spring_docker_path }}/docker-compose.yaml
|
||||
owner: root
|
||||
group: root
|
||||
mode: "644"
|
||||
lstrip_blocks: true
|
||||
- name: Start application docker container
|
||||
community.docker.docker_compose:
|
||||
project_src: /opt/{{ spring_docker_path }}
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
- name: Set up nginx for Spring Boot application
|
||||
ansible.builtin.import_tasks: nginx.yaml
|
||||
when: spring_use_nginx
|
||||
- name: Set up docker-compose
|
||||
ansible.builtin.import_tasks: docker.yaml
|
||||
@@ -0,0 +1,38 @@
|
||||
---
|
||||
- name: Add HTTP site
|
||||
ansible.builtin.template:
|
||||
src: etc/nginx/sites-available/spring_domain.conf.j2
|
||||
dest: /etc/nginx/sites-available/{{ spring_domain }}.conf
|
||||
owner: root
|
||||
group: root
|
||||
mode: "644"
|
||||
force: false
|
||||
lstrip_blocks: true
|
||||
- name: Disable default site
|
||||
ansible.builtin.command:
|
||||
cmd: rm /etc/nginx/sites-enabled/default
|
||||
removes: /etc/nginx/sites-enabled/default
|
||||
- name: Enable HTTP site
|
||||
ansible.builtin.command:
|
||||
cmd: ln -sf /etc/nginx/sites-available/{{ spring_domain }}.conf /etc/nginx/sites-enabled/{{ spring_domain }}.conf
|
||||
creates: /etc/nginx/sites-enabled/{{ spring_domain }}.conf
|
||||
notify: Reload nginx
|
||||
- name: Check certificate existence
|
||||
ansible.builtin.stat:
|
||||
path: "/etc/letsencrypt/live/{{ spring_domain }}/cert.pem"
|
||||
register: certificate
|
||||
- name: Generate certificates
|
||||
ansible.builtin.command:
|
||||
cmd: >
|
||||
certbot --nginx --non-interactive --keep-until-expiring
|
||||
--no-eff-email
|
||||
--email {{ admin_mail }}
|
||||
--redirect
|
||||
--renew-with-new-domains --agree-tos -d {{ spring_domain }}
|
||||
creates: "/etc/letsencrypt/live/{{ spring_domain }}/cert.pem"
|
||||
register: certbot_certificate_created
|
||||
notify: Reload nginx
|
||||
failed_when:
|
||||
- "'Successfully received certificate.' not in certbot_certificate_created.stdout"
|
||||
when:
|
||||
- not certificate.stat.exists
|
||||
@@ -0,0 +1,18 @@
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
|
||||
server_name {{ spring_domain }};
|
||||
|
||||
location ^~ /.well-known/acme-challenge/ {
|
||||
default_type "text/plain";
|
||||
}
|
||||
|
||||
{% for app in spring_apps %}
|
||||
{% if app.expose %}
|
||||
location {{ app.path }} {
|
||||
proxy_pass http://localhost:{{ app.port }};
|
||||
}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
version: '2'
|
||||
|
||||
services:
|
||||
{% for app in spring_apps %}
|
||||
{{ app.name }}:
|
||||
image: {{ app.image }}:{{ lookup('ansible.builtin.vars', app.name + '_image_version') }}
|
||||
{% if app.expose %}
|
||||
ports:
|
||||
- "{{ app.port }}:{{ app.port }}"
|
||||
{% else %}
|
||||
expose:
|
||||
- "{{ app.port }}"
|
||||
{% endif %}
|
||||
{% if 'depends_on' in app %}
|
||||
depends_on: {{ app.depends_on }}
|
||||
{% endif %}
|
||||
restart: always
|
||||
networks:
|
||||
- kafka
|
||||
{% if app.has_environment %}
|
||||
environment: {{ lookup('ansible.builtin.vars', app.name + '_environment') }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
networks:
|
||||
kafka:
|
||||
name: kafka
|
||||
external: true
|
||||
Reference in New Issue
Block a user