Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Ansible playbook: Location of file for task to copy file to target servers?

Tags:

ansible

As a proof of concept, I'm trying to create what is probably the simplest ansible playbook ever: copying a single file from the ansible server out to the server farm.

For completeness, ansible is installed properly. The ping module works great! LoL

The playbook for my POC reads:

---
- hosts: Staging
  tasks:
    - name: Copy the file
      copy: src=/root/Michael/file.txt dest=/tmp/file.txt

When I run the command...

ansible-playbook book.yml

I get the following output (summarized)...

msg: could not find src=/root/Michael/file.txt

Various docs and web pages I've read said the path to the file can either be absolute or relative to the playbook. I've tried both without success.

Where should my file be to get ansible to copy it over to the target servers?

Thanks!

like image 884
Michael J Avatar asked Sep 23 '13 17:09

Michael J


1 Answers

Found the error in my ways. The playbook and files were located in a directory that was not accessible to the account running the ansible-playbook command. So while the ansible-playbook process could read the playbook (i called the command from the directory where the file was located), the process could not read the directory where the file was located and as a result could not find the file.

The solution was to move the playbook and files into a directory that could be read by the account running ansible. After that, the playbook worked exactly as expected!

like image 181
Michael J Avatar answered Oct 19 '22 18:10

Michael J