I'm writing an ansible playbook for deploying a django app. As part of the process, I'd like to run the staticcollect
command.
我正在编写一个用于部署django应用程序的ansible playbook。作为该过程的一部分,我想运行staticcollect命令。
The issue I'm having is that the remote server has two python interpreters, one Python2.6 and one Python2.7, with Python2.6 being the default.
我遇到的问题是远程服务器有两个python解释器,一个Python2.6和一个Python2.7,Python2.6是默认的。
When I run the playbook, it runs using the Python2.6 interpretor and I need it to run against the Python2.7 interpretor.
当我运行playbook时,它使用Python2.6解释器运行,我需要它来运行Python2.7解释器。
Any idea on how this can be acheived?
有关如何实现这一点的任何想法?
My playbook is as follows:
我的剧本如下:
- 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
2 个解决方案
#1
0
/usr/bin/python
is just a symlink to either /usr/bin/python2.6
or /usr/bin/python2.7
. You can just invoke a bash command to update the symlink.
/ usr / bin / python只是/usr/bin/python2.6或/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
#2
0
I had a similar situation at the day job and solved it with the ansible_python_interpreter host/group variable.
我在当天的工作中遇到了类似的情况,并使用ansible_python_interpreter主机/组变量解决了这个问题。
The cool part is that you can define a different path for python on a host by host basis if you really need to.
很酷的部分是,如果你真的需要,你可以在主机的基础上为python定义不同的路径。
#1
0
/usr/bin/python
is just a symlink to either /usr/bin/python2.6
or /usr/bin/python2.7
. You can just invoke a bash command to update the symlink.
/ usr / bin / python只是/usr/bin/python2.6或/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
#2
0
I had a similar situation at the day job and solved it with the ansible_python_interpreter host/group variable.
我在当天的工作中遇到了类似的情况,并使用ansible_python_interpreter主机/组变量解决了这个问题。
The cool part is that you can define a different path for python on a host by host basis if you really need to.
很酷的部分是,如果你真的需要,你可以在主机的基础上为python定义不同的路径。