如下代码为《奔跑吧,Ansible》中得一段源码,结果在运行的时候提示目标地址不存在。
---
- name: Configure webserver with nginx
hosts: webservers
sudo: True
tasks:
- name: install nginx
apt: name=nginx update_cache=yes
- name: copy nginx config file
copy: src=files/nginx.conf dest=/etc/nginx/sites-available/default
- name: enable configuration
file: >
dest=/etc/nginx/sites-enabled/default
src=/etc/nginx/sites-available/default
state=link
- name: copy index.html
template: src=templates/index.html.j2 dest=/usr/share/nginx/html/index.html mode=0644
- name: restart nginx
service: name=nginx state=restarted
经过搜索资料发现,copy的参数最后如果是目录,则不会存在该报错,如果是文件则会存在该报错,而配置src=files/nginx.conf dest=/etc/nginx/sites-available/default
因为末尾没有反斜杠,被视为了文件,所以发生了该报错。