我正在尝试设置一个从源到目的地的符号链接,但不断点击
致命:[默认]:失败! => {“已更改”:false,“failed”:true,“msg”:“链接时出错:[Errno 2]没有这样的文件或目录”,“path”:“/ Applications / Xcode.app/Contents/Developer/Platforms /MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/config.h“,”state“: “不存在”}
观察到它显示状态缺席,即使状态是链接。
这是执行的任务:
- name: "Create ruby config.h symlink"
file:
src: "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin15/ruby/config.h"
dest: "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/config.h"
state: link
force: yes
when: xcode_version != "8.0"
文件存在:
ls -l /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin15/ruby/config.h
-rw-r--r-- 2 root wheel 7805 Jan 31 2016 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin15/ruby/config.h
注意:根据此处的讨论包括强制是 - Ansbible github issue
感谢任何帮助!
答案 0 :(得分:1)
我不确定丢失的目录是否是导致此问题的原因,但在创建指向该目录的链接之前确保目标目录存在是一个好习惯:
- name: Ensure that the directory exist
file:
path: "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby"
state: directory
mode: 0755
owner: root
group: wheel
- name: "Create ruby config.h symlink"
file:
...
答案 1 :(得分:0)
我的回答可能无法解决OP问题,但确实会导致此问题,因此可能会解释另一个遇到此问题的人。我经常发现这种错误可能是由链接名称中的末尾/
引起的。
例如,如下创建目录的任务将成功。
- name: ensure foobar directory exists
file:
state: directory
path: '/tmp/foobar/'
owner: 'foo'
group: 'bar'
mode: 0777
但是,后续的链接创建任务(如果编写如下)将导致您遇到错误。
- name: Establish link to foobar
file:
src: '/tmp/foobar/'
dest: '/local/baz/'
state: link
导致以下错误。
致命:[默认]:失败! => {“已更改”:false,“失败”:true,“ msg”: “链接时出错:[Errno 2]没有这样的文件或目录”,“路径”: “ ...”, “ state”:“缺席”}
按照以下说明删除/
可以解决此问题。
- name: Establish link to foobar
file:
src: '/tmp/foobar/'
dest: '/local/baz'
state: link