Python 许可证问题

Python 许可证问题,python,ansible,ansible-playbook,Python,Ansible,Ansible Playbook,我有一个创建文件的简单ansible任务: - name: create fake file file: name: /opt/refdata/PROD02/roman.delete state: touch 我为目标主机上运行的用户生成了公钥/私钥,并将公钥添加到授权密钥2中 当我尝试运行它时,会出现以下错误: failed: [experiment01] => {"failed": true, "parsed": false} Traceback (most r

我有一个创建文件的简单ansible任务:

- name: create fake file 
  file:
    name: /opt/refdata/PROD02/roman.delete
    state: touch
我为目标主机上运行的用户生成了公钥/私钥,并将公钥添加到授权密钥2中

当我尝试运行它时,会出现以下错误:

failed: [experiment01] => {"failed": true, "parsed": false}
Traceback (most recent call last):
  File "/home/acplus_uat01/.ansible/tmp/ansible-tmp-1441921944.69-3869708445827/file", line 1999, in <module>
    main()
  File "/home/acplus_uat01/.ansible/tmp/ansible-tmp-1441921944.69-3869708445827/file", line 372, in main
    open(path, 'w').close()
IOError: [Errno 2] No such file or directory: '/opt/refdata/PROD02/roman.delete'
在我运行ansible的同一个地方和同一个用户上运行这个:

cat test2.py | ssh -i ~/.ssh/myPrivateKey -q target_user@targethost python -
它创建了这个文件

所以,我的问题是-问题在哪里,为什么它不能创建一个文件

我运行剧本的方式如下:

ansible-playbook -i inventory/prod/ acc.yml -v --vault-password-file=~/.ansible-vault-pw --private-key ~/.ssh/myPrivateKey
我还尝试在/tmp/中创建一个文件,ansible成功了

编辑:所以,另一个更新-我将我正在将文件写入的目录设置为world writable(777),它创建了该文件。所以,问题是-这有什么不同

 cat test2.py | ssh -i ~/.ssh/myPrivateKey -q target_user@targethost python -

工作和通过Ansible做本质上相同的事情是不一样的

如果
/opt/refdata/PROD02/
不存在,您应该首先创建目录

file:
  name: /opt/refdata/PROD02
  state: directory
  recurse: yes
  mode: 0755
说:

递归-设置指定的文件属性(仅适用于state=目录

所以Ansible无法在一个命令中创建文件及其路径中的所有目录

然后使用第二个命令,您应该创建文件本身

name: create fake file 
  file:
    name: /opt/refdata/PROD02/roman.delete
    state: touch

由于ansible playbook可以在/tmp中写入文件,但不能在此处写入文件,我会在游戏中添加一个步骤来调试:var=ansible\u ssh\u user,并检查与运行python脚本的用户是否匹配。我只需从ansible中触摸/tmp/foo,然后查看/tmp/foo的权限和所有权,以验证ansible是否正在使用您期望的属性创建该文件。它是使用我期望的属性创建-正确的用户/group@RomanGoyenko,是否为NFS卷?您是否使用
sudo:yes
运行剧本?PROD2上是否设置了
nosuid
标志(如果是单独安装)?如果其中一个是真的,我可以解释这种行为……您是否尝试过使用“-vvv”?/opt/refdata/PROD02/运行剧本
name: create fake file 
  file:
    name: /opt/refdata/PROD02/roman.delete
    state: touch