设置符号链接错误 - Ansible

Sus*_*n N 4 symlink ansible ansible-playbook

我正在尝试设置从源到目标的符号链接,但继续点击

致命:[默认]:失败!=> {"changed": 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"
Run Code Online (Sandbox Code Playgroud)

文件已存在:

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
Run Code Online (Sandbox Code Playgroud)

注意:根据此处的讨论包含强制是 - Ansbible github 问题

任何帮助表示赞赏!

小智 7

我的回答可能没有解决 OP 问题,但它肯定会导致此问题,因此可能会解释另一个遇到此问题的人。我经常发现这样的错误可能是由/链接名称中的尾随引起的。

例如,创建如下目录的任务将成功。

- name: ensure foobar directory exists
  file: 
    state: directory
    path: '/tmp/foobar/'
    owner: 'foo'    
    group: 'bar'
    mode: 0777
Run Code Online (Sandbox Code Playgroud)

但是,后续的链接创建任务,如果如下编写,将导致您遇到的错误。

- name: Establish link to foobar
  file:
    src: '/tmp/foobar/'
    dest: '/local/baz/'
    state: link
Run Code Online (Sandbox Code Playgroud)

导致以下错误。

致命:[默认]:失败!=> {"changed": false, "failed": true, "msg": "链接时出错: [Errno 2] 没有那个文件或目录", "path": "...", "state": "缺席的”}

删除/如下所示,可以解决这个问题。

- name: Establish link to foobar
  file:
    src: '/tmp/foobar/'
    dest: '/local/baz'
    state: link
Run Code Online (Sandbox Code Playgroud)

  • 是的,遇到了与OP相同的错误,它确实是尾随的“/”。谢谢! (2认同)

Pas*_*i H 2

我不确定丢失的目录是否是导致问题的原因,但在创建指向该目录的链接之前确保目标目录存在是一个很好的做法:

- 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:
  ...
Run Code Online (Sandbox Code Playgroud)