简体   繁体   English

使用yaml文件在虚拟环境中运行本地python脚本

[英]run local python script inside virtual environment using yaml file

I want to run my local python script inside virtual environment. 我想在虚拟环境中运行本地python脚本。 Here is the code I have tried. 这是我尝试过的代码。 I have created virtual environment and installed Cassandra-driver as well 我已经创建了虚拟环境并安装了Cassandra驱动程序

---
- hosts: localhost
  gather_facts: no
  connection: local
  name: install cassendra-driver
  become: true
  become_user: root
  vars:
    PROJECT_HOME: "/home/hari/Desktop/venvs"
  tasks:
          - name: Run a script using an executable in virtual environment
                    script: "/space/code_base/add_new_column_to_table.py"
                    virtualenv: "{{ PROJECT_HOME }}/myenv"
                    args:
                        executable: python2

But I am getting error 但是我出错了

  • ERROR! 错误! Syntax Error while loading YAML. 加载YAML时的语法错误。 mapping values are not allowed in this context 在这种情况下,不允许使用映射值

The error appears to be in '/home/hari/Desktop/cassendra-driver_2.yml': line 30, column 27, but may be elsewhere in the file depending on the exact syntax problem. 该错误似乎在“ /home/hari/Desktop/cassendra-driver_2.yml”中:第30行,第27列,但根据确切的语法问题,可能在文件的其他位置。

The offending line appears to be: 令人反感的行似乎是:

      - name: Run a script using an executable in virtual environment
                script: "/space/code_base/add_new_column_to_table.py"
                      ^ here

* *

Could some one help me? 有人可以帮我吗?

My requirement is to run local python script inside virtual environment. 我的要求是在虚拟环境中运行本地python脚本。

I don't have access to your environment, but something like this should work: 我无法访问您的环境,但是这样的方法应该起作用:

tasks:
- command: {{ PROJECT_HOME }}/myenv/bin/python /space/code_base/add_new_column_to_table.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM