无法通过ansible从localhost运行python脚本

时间:2016-09-26 12:45:01

标签: python ansible ansible-playbook

我的结构如下:

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

1 个答案:

答案 0 :(得分:2)

你在这一行有一个错字:

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

您不应该使用引号括起变量。而是将行更改为:

    chdir: '{{ role_path }}/files'

这应该有效!