--- - name: Clone Git repository to /opt and set permissions hosts: Rx_server become: yes # برای اجرای دستورات با دسترسی ریشه vars: git_username: tester git_password: Datall@0000 app_path: /opt/DataDiodeRServer venv_path: "{{ app_path }}/.env" tasks: #section clone in git - name: Remove existing DataDiodeRServer directory file: path: /opt/DataDiodeRServer state: absent - name: Clone the repository git: repo: "https://{{ git_username }}:{{ git_password | replace('@', '%40') }}@gitea.datall.ir/Software/DataDiodeRServer.git" dest: /opt/DataDiodeRServer update: yes - name: Change ownership of the directory file: path: /opt/DataDiodeRServer owner: datall group: users state: directory #section active python and install requirements - name: Create a Python 3 venv become_user: datall ansible.builtin.command: cmd: python3 -m venv "{{ venv_path }}" args: creates: "{{ venv_path }}/bin/activate" - name: Upgrade pip & setuptools inside the venv ansible.builtin.command: cmd: "{{ venv_path }}/bin/python -m pip install --upgrade pip setuptools" - name: Install requirements into the venv become_user: datall ansible.builtin.pip: requirements: "{{ app_path }}/requirements.txt" virtualenv: "{{ venv_path }}" virtualenv_command: python3 -m venv virtualenv_site_packages: no #section copy scripts to path - name: Copy all scripts from scripts directory to /usr/sbin copy: src: /opt/DataDiodeRServer/scripts/ dest: /usr/sbin/ owner: root group: root mode: '0755' recurse: yes #section copy systemd file enable and start - name: Copy datadiode.service to /etc/systemd/system/ copy: src: /opt/DataDiodeRServer/service/datadiode.service dest: /etc/systemd/system/datadiode.service owner: root group: root mode: '0644' remote_src: yes - name: Reload systemd daemon command: systemctl daemon-reload - name: Enable and start datadiode service systemd: name: datadiode.service enabled: yes state: started