Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Erro ao subir o banco de dados

ao tentar executar o playbook o seguinte erro está ocorrendo: fatal: [35.162.80.147]: FAILED! => {"changed": true, "cmd": ". /home/ubuntu/tcc/venv/bin/activate; python /home/ubuntu/tcc/manage.py migrate", "delta": "0:00:00.041711", "end": "2024-09-03 07:25:22.721105", "msg": "non-zero return code", "rc": 1, "start": "2024-09-03 07:25:22.679394", "stderr": "Traceback (most recent call last):\n File "/home/ubuntu/tcc/manage.py", line 11, in main\n from django.core.management import execute_from_command_line\n File "/home/ubuntu/tcc/venv/lib/python3.12/site-packages/django/init.py", line 1, in \n from django.utils.version import get_version\n File "/home/ubuntu/tcc/venv/lib/python3.12/site-packages/django/utils/version.py", line 6, in \n from distutils.version import LooseVersion\nModuleNotFoundError: No module named 'distutils'\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File "/home/ubuntu/tcc/manage.py", line 22, in \n main()\n File "/home/ubuntu/tcc/manage.py", line 13, in main\n raise ImportError(\nImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?", "stderr_lines": ["Traceback (most recent call last):", " File "/home/ubuntu/tcc/manage.py", line 11, in main", " from django.core.management import execute_from_command_line", " File "/home/ubuntu/tcc/venv/lib/python3.12/site-packages/django/init.py", line 1, in ", " from django.utils.version import get_version", " File "/home/ubuntu/tcc/venv/lib/python3.12/site-packages/django/utils/version.py", line 6, in ", " from distutils.version import LooseVersion", "ModuleNotFoundError: No module named 'distutils'", "", "The above exception was the direct cause of the following exception:", "", "Traceback (most recent call last):", " File "/home/ubuntu/tcc/manage.py", line 22, in ", " main()", " File "/home/ubuntu/tcc/manage.py", line 13, in main", " raise ImportError(", "ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?"], "stdout": "", "stdout_lines": []}

3 respostas

o playbook está com o seguinte código:

- hosts: terraform-ansible
  tasks: 
  - name: Instalando o python3, virtualenv
    apt:
      pkg:
      - python3
      - virtualenv
      update-cache: yes
    become: yes
  - name: Git Clone
    ansible.builtin.git:
      repo: https://github.com/alura-cursos/clientes-leo-api.git
      dest: /home/ubuntu/tcc
      version: master
      force: yes
  - name: Instalando dependencias com pip (Django e Django Rest)
    pip:
      virtualenv: /home/ubuntu/tcc/venv
      requirements: /home/ubuntu/tcc/requirements.txt 
  - name: Alterando o hosts do settings
    lineinfile:
      path: /home/ubuntu/tcc/setup/settings.py
      regexp: 'ALLOWED_HOSTS'
      line: 'ALLOWED_HOSTS = ["*"]'
      backrefs: yes
  - name: configurando o banco de dados
    shell: '. /home/ubuntu/tcc/venv/bin/activate; python /home/ubuntu/tcc/manage.py migrate'
  - name: carregando os dados iniciais
    shell: '. /home/ubuntu/tcc/venv/bin/activate; python /home/ubuntu/tcc/manage.py loaddata clientes.json'
solução!

Experimente criar a seguinte task antes da task "configurando banco de dados":

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

criei a seguinte tarefa antes de configurar o banco de dados

 - name: Atualizando pip, setuptools e wheel
    pip:
      virtualenv: /home/ubuntu/tcc/venv
      name:
        - pip
        - setuptools
        - wheel
      state: latest

resolveu.