From 8b4211463fdc11fce322dfc15743c946c8960d40 Mon Sep 17 00:00:00 2001 From: Josh Karamuth Date: Wed, 23 Oct 2024 20:32:19 +0400 Subject: [PATCH] Update django role --- ansible/roles/django/tasks/main.yml | 88 ++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 9 deletions(-) diff --git a/ansible/roles/django/tasks/main.yml b/ansible/roles/django/tasks/main.yml index a1d4ac9..f50e145 100644 --- a/ansible/roles/django/tasks/main.yml +++ b/ansible/roles/django/tasks/main.yml @@ -1,14 +1,84 @@ --- -- name: Ensure django user exists - ansible.builtin.user: - name: django - state: present - shell: /bin/bash +- name: Ensure docker is setup + block: + - name: Setup docker apt key + ansible.builtin.apt_key: + url: "https://download.docker.com/linux/ubuntu/gpg" + keyring: /etc/apt/trusted.gpg.d/docker.gpg + state: present + + - name: Setup docker repository + ansible.builtin.apt_repository: + repo: "deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/docker.gpg] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable" + + - name: Ensure docker packages are present + ansible.builtin.apt: + name: + - docker-ce + - docker-ce-cli + - containerd.io + - docker-buildx-plugin + - docker-compose-plugin + state: present + update_cache: true + +- name: Ensure config directory exists + ansible.builtin.file: + path: /etc/simple_django + state: directory + owner: "{{ admin_username }}" + group: "{{ admin_username }}" + mode: "u=rwx,g=rwx,o=rx" - name: Copy appconfig ansible.builtin.copy: src: appconfig.env - dest: /home/django/appconfig.env - owner: django - group: django - mode: "u=r,g=r,o=" + dest: /etc/simple_django/appconfig.env + owner: "{{ admin_username }}" + group: "{{ admin_username }}" + mode: "u=rw,g=rw,o=r" + +- name: Ensure docker-exports directory is present + ansible.builtin.file: + path: /var/docker-exports + state: directory + owner: "{{ admin_username }}" + group: "{{ admin_username }}" + mode: "u=rwx,g=rwx,o=" + +- name: Ensure data volume is present + community.docker.docker_volume: + volume_name: simpe_django_data + +- name: Ensure deployment systemd service is setup + block: + - name: Copy deployment path unit + ansible.builtin.copy: + src: deploy-app.path + dest: /etc/systemd/system/deploy-app.path + owner: root + group: root + mode: "u=r,g=r,o=r" + + - name: Copy deployment service unit + ansible.builtin.copy: + src: deploy-app.service + dest: /etc/systemd/system/deploy-app.service + owner: root + group: root + mode: "u=r,g=r,o=r" + + - name: Copy deployment service unit + ansible.builtin.copy: + src: deploy-app.py + dest: /usr/local/bin/deploy-app.py + owner: root + group: root + mode: "u=rx,g=rx,o=" + + - name: Ensure path unit is enabled and started + ansible.builtin.systemd_service: + name: deploy-app.path + state: started + daemon_reload: true + enabled: true