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

unable to run a python script from localhost via ansible

我的结构如下:

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

我需要 运行 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'

但这找不到文件并说:

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

您在这一行中有错字:

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

您不应该用引号将变量括起来。相反,将该行更改为:

    chdir: '{{ role_path }}/files'

那应该行得通!