我正在使用以下脚本:
http://mattupstate.com/python/devops/2012/08/07/flask-wsgi-application-deployment-with-ubuntu-ansible-nginx-supervisor-and-uwsgi.html

我已将脚本更新为以下内容:
setup_server.yml

- name: Install python packages
  hosts: webservers
  user: ubuntu
  sudo: yes
  tasks:
    - name: add nginx ppa
      apt_repository:
        repo: "ppa:nginx/stable"

    - name: install common packages needed for python application development
      apt:
        name: "{{ item }}"
      with_items:
        - libpq-dev
        - libmysqlclient-dev
        - libxml2-dev
        - libjpeg62
        - libjpeg62-dev
        - libfreetype6
        - libfreetype6-dev
        - zlib1g-dev
        - mysql-client
        - python-dev
        - python-setuptools
        - python-imaging
        - python-mysqldb
        - python-psycopg2
        - git-core
        - nginx

    - name: install pip
      easy_install:
        name: pip

    - name: install various libraries with pip
      pip:
        name: "{{ item }}"
      with_items:
        - virtualenv
        - supervisor
        - uwsgi

    - name: symlink imaging library files
      file: src=/usr/lib/x86_64-linux-gnu/libfreetype.so dest=/usr/lib/libfreetype.so state=link

    - name: symlink imaging library files
      file: src=/usr/lib/x86_64-linux-gnu/libz.so dest=/usr/lib/libz.so state=link

    - name: symlink imaging library files
      file: src=/usr/lib/x86_64-linux-gnu/libjpeg.so.62 dest=/usr/lib/x86_64-linux-gnu/libjpeg.so state=link

    - name: symlink imaging library files
      file: src=/usr/lib/x86_64-linux-gnu/libjpeg.so dest=/usr/lib/libjpeg.so state=link

    - name: remove default nginx site
      file: path=/etc/nginx/sites-enabled/default state=absent

    - name: write nginx.conf
      template: src=templates/nginx.conf dest=/etc/nginx/nginx.conf

    - name: create supervisord config folder
      file: dest=/etc/supervisor state=directory owner=root

    - name: create supervisord config
      template: src=templates/supervisord.conf dest=/etc/supervisor/supervisord.conf

    - name: create supervisord init script
      template: src=templates/supervisord.sh dest=/etc/init.d/supervisord mode=0755

    - name: start supervisord service and have it run during system startup
      service: name=supervisord state=started enabled=yes

    - name: create webapps directory
      file: dest=/srv/webapps state=directory


和:
deploy.yml

- name: Setup webser
  hosts: webservers
  user: ubuntu
  sudo: True

  vars:
    app_name: hello_flask
    repo_url: https://github.com/mattupstate/ansible-tutorial.git
    repo_remote: origin
    repo_version: master
    webapps_dir: /srv/webapps
    wsgi_file: wsgi.py
    wsgi_callable: app

  tasks:
    - name: ensure log directory
      file: path={{ webapps_dir }}/{{ app_name }}/log state=directory mode=0755

    - name: deploy code from repository
      synchronize: src=/Users/ankitjain/dev/virel/ansible-tutorial/ dest={{ webapps_dir }}/{{ app_name }}/src archive=yes delete=yes rsync_opts="--exclude='tags' --exclude='.git' --exclude='*.swp'" rsync_path='sudo rsync'

    - name: install dependencies into virtualenv
      pip: requirements={{ webapps_dir }}/{{ app_name }}/src/requirements.txt virtualenv={{ webapps_dir }}/{{ app_name }}/venv state=present

    - name: create supervisor program config
      template: src=templates/supervisor.ini dest=/etc/supervisor/{{ app_name }}.ini
      notify:
        - restart app

    - name: create nginx site config
      template: src=templates/nginx_site.conf dest=/etc/nginx/sites-available/{{ app_name }}.conf
      notify:
        - restart nginx

    - name: link nginx config
      file: src=/etc/nginx/sites-available/{{ app_name }}.conf dest=/etc/nginx/sites-enabled/{{ app_name }}.conf state=link

    - name: start app
      supervisorctl: name={{ app_name }} state=started

  handlers:
    - name: restart app
      supervisorctl: name={{ app_name }} state=restarted

    - name: restart nginx
      service: name=nginx state=restarted


我已验证如果在本地运行该源,则可以正常工作。正确复制了所有变量。主管运行正常。因此,nginx config设置正确,我能够直接启动网络服务器。

但是主管无法启动Web服务器。我收到以下错误:
hello_flask:错误(异常终止)

我不确定如何调试

最佳答案

通过SSH登录服务器
手动使用主管启动该过程。主管文档:http://supervisord.org/
如果需要,请手动编辑主管配置文件,以使主管输出stdout和stderr一个文件,您可以随时查看通过主管启动时应用程序正在打印出什么错误消息

关于python - Flask Ansible错误通过主管启动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31954429/

10-11 17:42