From 95b73daa36b23565a8566f71f9b202d3459b685f Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Sun, 25 Jun 2023 09:52:36 -0400 Subject: Initial Commit --- roles/services/containers/nextcloud/tasks/main.yml | 184 +++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 roles/services/containers/nextcloud/tasks/main.yml (limited to 'roles/services/containers/nextcloud/tasks') diff --git a/roles/services/containers/nextcloud/tasks/main.yml b/roles/services/containers/nextcloud/tasks/main.yml new file mode 100644 index 0000000..fbd4a76 --- /dev/null +++ b/roles/services/containers/nextcloud/tasks/main.yml @@ -0,0 +1,184 @@ +- name: set image fact + set_fact: + image: nextcloud:27.0.0-apache + +- name: set other facts + set_fact: + repo_tag: "{{ image }}" + custom_registry: "{{ docker_registry_url + '/' + docker_registry_username }}" + +- name: create nextcloud directory + file: + path: "{{ docker_home }}/nextcloud" + state: directory + owner: "{{ docker_username }}" + group: "{{ docker_username }}" + mode: '0755' + +- name: create nextcloud app directory + file: + path: "{{ docker_home }}/nextcloud/app/" + state: directory + owner: "{{ docker_username }}" + group: "{{ docker_username }}" + mode: '0755' + +- name: create nextcloud data directory + file: + path: "{{ docker_home }}/nextcloud/data/" + state: directory + owner: "{{ docker_username }}" + group: "{{ docker_username }}" + mode: '0755' + +- name: login to docker registry + become: yes + become_user: "{{ docker_username }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" + docker_login: + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + registry_url: "{{ docker_registry_url }}" + username: "{{ docker_registry_username }}" + password: "{{ docker_registry_password }}" + +- name: pull and push nextcloud image + become: yes + become_user: "{{ docker_username }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" + docker_image: + name: "{{ image }}" + repository: "{{ custom_registry }}/{{ repo_tag }}" + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + source: pull + force_source: yes + push: yes + +- name: create nextcloud docker network + docker_network: + name: "{{ nextcloud_network_name }}" + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + driver: bridge + ipam_config: + - subnet: "{{ nextcloud_subnet }}" + gateway: "{{ nextcloud_gateway }}" + +- name: create and deploy postgres container + become: yes + become_user: "{{ docker_username }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" + docker_container: + name: "nextcloud-postgres" + hostname: "nextcloud-postgres" + image: "postgres:alpine" + pull: yes + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + purge_networks: yes + networks: + - name: "{{ nextcloud_network_name }}" + ipv4_address: "{{ nextcloud_postgres_ipv4 }}" + state: 'started' + comparisons: + '*': strict + restart_policy: unless-stopped + env: + "POSTGRES_USER": "{{ nextcloud_postgres_user }}" + "POSTGRES_PASSWORD": "{{ nextcloud_postgres_password }}" + "POSTGRES_DB": "{{ nextcloud_postgres_db }}" + volumes: + - "{{ docker_home }}/nextcloud/data:/var/lib/postgresql/data" + +- name: create and deploy redis container + become: yes + become_user: "{{ docker_username }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" + docker_container: + name: "nextcloud-redis" + hostname: "nextcloud-redis" + image: "redis:alpine" + pull: yes + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + purge_networks: yes + networks: + - name: "{{ nextcloud_network_name }}" + ipv4_address: "{{ nextcloud_redis_ipv4 }}" + state: 'started' + comparisons: + '*': strict + restart_policy: unless-stopped + +- name: create and deploy nextcloud container + become: yes + become_user: "{{ docker_username }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" + docker_container: + name: "nextcloud" + hostname: "nextcloud" + image: "{{ custom_registry }}/{{ repo_tag }}" + pull: yes + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + purge_networks: yes + networks: + - name: "{{ nextcloud_network_name }}" + ipv4_address: "{{ nextcloud_ipv4 }}" + ports: + - "127.0.0.1:{{ nextcloud_external_port }}:80" + state: 'started' + comparisons: + '*': strict + restart_policy: unless-stopped + env: + "POSTGRES_USER": "{{ nextcloud_postgres_user }}" + "POSTGRES_PASSWORD": "{{ nextcloud_postgres_password }}" + "POSTGRES_DB": "{{ nextcloud_postgres_db }}" + "POSTGRES_HOST": "nextcloud-postgres" + "REDIS_HOST": "nextcloud-redis" + "NEXTCLOUD_ADMIN_USER": "{{ nextcloud_admin }}" + "NEXTCLOUD_ADMIN_PASSWORD": "{{ nextcloud_admin_password }}" + "NEXTCLOUD_TRUSTED_DOMAINS": "{{ nextcloud_trusted_domains }}" + volumes: + - "{{ docker_home }}/nextcloud/app:/var/www/html" + +- name: create and deploy nextcloud cron container + become: yes + become_user: "{{ docker_username }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" + docker_container: + name: "nextcloud-cron" + hostname: "nextcloud-cron" + image: "{{ custom_registry }}/{{ repo_tag }}" + entrypoint: "/cron.sh" + pull: yes + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + purge_networks: yes + networks: + - name: "{{ nextcloud_network_name }}" + ipv4_address: "{{ nextcloud_cron_ipv4 }}" + state: 'started' + recreate: yes + restart_policy: unless-stopped + volumes: + - "{{ docker_home }}/nextcloud/app:/var/www/html" + +- name: deploy nginx configuration + notify: restart nginx + register: nginx_config + copy: + src: "{{ nextcloud_nginx_config }}" + dest: /etc/nginx/sites-available/nextcloud.conf + owner: root + group: root + mode: '0644' + +- name: symlink site + file: + src: /etc/nginx/sites-available/nextcloud.conf + dest: /etc/nginx/sites-enabled/nextcloud.conf + owner: root + group: root + state: link -- cgit v1.2.3