简体   繁体   English

无法通过Ansible从本地主机运行python脚本

[英]unable to run a python script from localhost via ansible

I have my structure as : 我的结构如下:

playbooks_only 
    |
    |- read_replica_boto3.yml
    |- roles
         |
         |-read_replica_boto3
                 |-defaults
                 |-tasks-->> main.yml                      
                 |-files-->> - rds_read_replica_ops.py
                             - sample.yml

I need to run the rds_read_replica_ops.py , i wrote the following : 我需要运行rds_read_replica_ops.py,我编写了以下内容:

- name: Create a cross-region replica using boto3 script
  command:  python rds_read_replica_ops.py sample.yml
  args:
    chdir: '"{{ role_path }}"/files'

But this can't find the file and says: 但这找不到文件,并说:

sg: cannot change to directory '/home/blah/recovery/playbooks_only/"/home/blah/recovery/playbooks_only/roles/read_replica_boto3"/files': path does not exist

FATAL: all hosts have already failed -- aborting

You have a typo in this line: 您在此行中有错别字:

    chdir: '"{{ role_path }}"/files'

You shouldn't surround variables with quotes. 您不应该在变量两边加上引号。 Instead, change the line to: 而是将行更改为:

    chdir: '{{ role_path }}/files'

And that should work! 那应该工作!

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

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