nginx – ansible symlink的正确语法

使用ansible创建符号链接的正确语法是什么?
我正在创建一个Vagrant虚拟环境并运行ansible作为我的配置器.一切正常,直到我尝试从启用网站的符号链接到我的网站nginx配置文件.这是我尝试过的.

- name: Create symlink to example.com
  file: 
    path: /etc/nginx/sites-enabled/example.com 
    dest: /etc/nginx/sites-available/example.com 
    state: link
  notify: nginx reload

当我这样做时,我遇到了以下错误.

ERROR: Syntax Error while loading YAML script, /Users/username/project/ansible/roles/nginx/tasks/main.yml

Note: The error may actually appear before this position: line 24, column 1

– name: Symlink to example.dev.conf

file: path=/etc/nginx/sites-enabled/example.dev.conf

state=link

^ Ansible failed to complete successfully. Any error output should be visible above.
Please fix these errors and try again.

我也尝试过使用src = / etc / nginx / sites-enabled而不是路径,但我似乎无法在网上找到这个明确的例子.

眼镜:

> OSX Mavericks
>流浪汉1.6.3
> VirtualBox 4.3
> nginx 1.6.0
> ansible 1.6.2
> ubuntu 14.04

解决方法:

the documentation开始:

src, path of the file to link to (applies only to state=link). Will accept absolute, relative and nonexisting paths. Relative paths are not expanded.

使用state = link时需要使用src和dest,而不是path.您还需要反转您的源和目标,这似乎是错误的方式(假设您真的想要链接到站点 – 可从站点启用) – src是链接到的路径,dest是创建的位置符号链接.

- name: Create symlink to example.com
  file: src=/etc/nginx/sites-available/example.com dest=/etc/nginx/sites-enabled/example.com state=link
  notify: nginx reload
上一篇:linux – Vagrant ssh不显示命令提示符


下一篇:vagrant centos lamp小记