Ansible Django模块替代Python解释器

Vac*_*zal 5 python django ansible

我正在编写一个用于部署django应用程序的ansible playbook.作为该过程的一部分,我想运行该staticcollect命令.

我遇到的问题是远程服务器有两个python解释器,一个是Python2.6,一个是Python2.7,Python2.6是默认的.

当我运行playbook时,它使用Python2.6解释器运行,我需要它来运行Python2.7解释器.

有关如何实现这一点的任何想法?

我的剧本如下:

- hosts: xxxxxxxxx
  vars:
    hg_branch:  dmv2
    django_dir: /opt/app/xxxx
    conf_file:  /opt/app/conf/xx_uwsgi.ini
    django_env:
        STATIC_ROOT: /opt/app/serve/static
  remote_user: xxxxxx
  tasks:
  - name: Update the hg repo
    command: chdir=/opt/app/xxxxx  hg pull -u --rev {{hg_branch}}
  - name: Collect static resources
    environment: django_env
    django_manage: command=collectstatic app_path={{django_dir}}
  - name: Restart the django service
    command: touch {{conf_file}}
  - name: check nginx is running
    service: name=nginx state=started
Run Code Online (Sandbox Code Playgroud)

pzt*_*ick 0

/usr/bin/python只是/usr/bin/python2.6or的符号链接/usr/bin/python2.7。您只需调用 bash 命令即可更新符号链接。

- name: Remove python --> python2.6 symlink
  sudo: yes
  command: rm /usr/bin/python

- name: Add python --> python2.7 symlink
  sudo: yes
  command: ln -s /usr/bin/python2.7 /usr/bin/python
Run Code Online (Sandbox Code Playgroud)