From 97fc92ff563cd6fbb3b964cf8199666ff8f14e9a Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Wed, 23 Aug 2023 20:48:34 -0400 Subject: [PATCH] roles/containers: added gitea container --- group_vars/bastion/vars.yml | 8 ----- group_vars/fleet/vars.yml | 12 -------- roles/containers/defaults/main.yml | 6 ++++ roles/containers/tasks/main.yml | 23 +++++++++++++++ .../templates/docker-compose.yml.j2 | 29 +++++++++++++++++++ run.yml | 5 ++++ 6 files changed, 63 insertions(+), 20 deletions(-) delete mode 100644 group_vars/fleet/vars.yml create mode 100644 roles/containers/defaults/main.yml create mode 100644 roles/containers/tasks/main.yml create mode 100644 roles/containers/templates/docker-compose.yml.j2 diff --git a/group_vars/bastion/vars.yml b/group_vars/bastion/vars.yml index af95d6c..912a118 100644 --- a/group_vars/bastion/vars.yml +++ b/group_vars/bastion/vars.yml @@ -3,12 +3,4 @@ # set these in host vars # these are mostly defaults -- services: - - "sshd" - - "ddclient" - - "caddy" - - "website" - - "nameserver" - - "mailserver" - enable_ddclient: true diff --git a/group_vars/fleet/vars.yml b/group_vars/fleet/vars.yml deleted file mode 100644 index e12f2e1..0000000 --- a/group_vars/fleet/vars.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- - -# set these in host vars -# these are mostly defaults - -- services: - - "sshd" - - "mailserver" - - "gitea" - - "synapse" - - "navidrome" - - "syncthing" diff --git a/roles/containers/defaults/main.yml b/roles/containers/defaults/main.yml new file mode 100644 index 0000000..cd69172 --- /dev/null +++ b/roles/containers/defaults/main.yml @@ -0,0 +1,6 @@ +--- + +# these are defaults +# change these in group/host vars + +docker_compose_dir: "/home/{{ ansible_user }}/services" diff --git a/roles/containers/tasks/main.yml b/roles/containers/tasks/main.yml new file mode 100644 index 0000000..86c6f7b --- /dev/null +++ b/roles/containers/tasks/main.yml @@ -0,0 +1,23 @@ +--- + +- name: Install Docker packages + community.general.pacman: + name: + - docker + - docker-compose + +- name: Create docker-compose directory + ansible.builtin.file: + path: "{{ docker_compose_dir }}" + owner: "{{ admin_username }}" + group: "{{ admin_username }}" + state: directory + +- name: Generate docker-compose.yml + template: + src: "docker-compose.yml" + dest: "{{ docker_compose_dir }}/docker-compose.yml" + +- name: Docker compose up + community.docker.docker_compose: + project_src: "{{ docker_compose_dir }}" diff --git a/roles/containers/templates/docker-compose.yml.j2 b/roles/containers/templates/docker-compose.yml.j2 new file mode 100644 index 0000000..3857280 --- /dev/null +++ b/roles/containers/templates/docker-compose.yml.j2 @@ -0,0 +1,29 @@ +# vim: ft=yaml +--- + +version: "3" + +networks: + gitea: + external: false + +services: +{% if "gitea" in group_names %} + gitea: + container_name: gitea + image: gitea/gitea:latest + environment: + - USER=gitea + restart: unless-stopped + networks: + - gitea + volumes: + - {{ dataroot }}/gitea:/data + - {{ }} + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + ports: + - "3000:3000" + - "222:22" + +{% endif %} diff --git a/run.yml b/run.yml index d8792e2..259158d 100644 --- a/run.yml +++ b/run.yml @@ -86,3 +86,8 @@ tags: - website when: "website" in group_names + + - role: containers + tags: + - containers + when: "fleet" in group_names