这个错误通常是由于在模板中引用了未定义的变量所引起的。解决方法是在playbook或role中定义所有变量,在copy模块中明确使用它们。
以下是一个例子:
- name: Copy file with defined variables
hosts: web
vars:
my_file: /path/to/source/file.txt
destination: /path/to/destination/
tasks:
- name: Copying file using variables
copy:
src: "{{ my_file }}"
dest: "{{ destination }}"
mode: 0700
become: yes
在这个例子中,我们定义了my_file和destination变量,并在copy模块中明确使用它们。确保在编写playbook或role时遵循这种模式,可以帮助避免这种错误的出现。