" [Errno 13]权限被拒绝错误"在Ansible中运行Py脚本时

时间:2017-01-27 08:38:43

标签: ansible

当我通过Ansible playbook运行Python脚本时,我收到以下错误:

fatal: [localhost]: FAILED! => {"changed": false, "cmd": "/Dest/To/Repo/HW.py", "failed": true, "msg": "[Errno 13] Permission denied", "rc": 13}

我添加了sudo: yes行:

这是我的yaml文件:

- name: a play that runs entirely on the ansible host
  hosts: 127.0.0.1
  sudo: yes
  connection: local
  tasks:
  - name: check out a git repository
    git: repo={{ repo_url }} dest=/Dest/To/Repo/ accept_hostkey=yes
    vars:
      repo_url: https://github.com/lorin/mezzanine-example.git

  - name: Running the Python Script
    command: /Dest/To/Repo/HW.py

HW.py脚本只是print("Hello World")

关于权限错误,我需要做些什么吗?

1 个答案:

答案 0 :(得分:2)

您需要使用umask在git模块调用中添加执行权限:

- name: a play that runs entirely on the ansible host
  hosts: 127.0.0.1
  sudo: yes
  connection: local
  tasks:
  - name: check out a git repository
    git: repo={{ repo_url }} dest=/Dest/To/Repo/ accept_hostkey=yes
    umask: 0022
    vars:
      repo_url: https://github.com/lorin/mezzanine-example.git