# Ad-Hoc Works; Playbook Works. Wait... No it doesn't.

**URL:** <https://forum.ansible.com/t/ad-hoc-works-playbook-works-wait-no-it-doesnt/17174>\
**Category:** Ansible Project\
**Created:** [January 3, 2015, 3:55pm UTC](https://forum.ansible.com/t/ad-hoc-works-playbook-works-wait-no-it-doesnt/17174 "2015-01-03T15:55:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Short](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Short](https://forum.ansible.com/u/Chris_Short)\
**Post date:** [January 3, 2015, 3:55pm UTC](https://forum.ansible.com/t/ad-hoc-works-playbook-works-wait-no-it-doesnt/17174/1 "2015-01-03T15:55:56Z")

</div>

This ad-hoc command works for me:

ansible -s -m copy -a “src=roles/pi\_ddclient/files/etc/ddclient.conf dest=/etc/ddclient.conf owner=root group=root mode=0600 backup=yes” daffy

However when I run the playbook containing the same command (with sudo: true specified) it does not copy the file into place (no modification to the file at all) but the play says it runs successfully!

cshort-mba:ansible oaf357$ ansible-playbook pi\_ddclient.yml -s  
sudo password:

PLAY [daffy] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [daffy]

TASK: [common | apt-get update] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [daffy]

TASK: [common | Installing commonly installed files] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [daffy] =\> (item=curl,host,mercurial,ntpdate,vim)

TASK: [common | Make Vim Default Editor] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [daffy]

TASK: [pi\_ddclient | Install ddclient] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [daffy] =\> (item=ddclient)

TASK: [pi\_ddclient | Copy /etc/ddclient.conf and /etc/defaults/ddclient to server] \*\*\*  
ok: [daffy]

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
daffy : ok=6 changed=1 unreachable=0 failed=0

Here’s the pi\_ddclient.yml file:

---

<div class="post-metadata">

**Author:** ![Greg\_Andrews](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@Greg\_Andrews](https://forum.ansible.com/u/Greg_Andrews)\
**Post date:** [January 4, 2015, 3:52pm UTC](https://forum.ansible.com/t/ad-hoc-works-playbook-works-wait-no-it-doesnt/17174/2 "2015-01-04T15:52:06Z")

</div>

I believe the primary issue is that your pi\_ddclient role’s task file specifies the same path to the source file as your ad-hoc command. Your ad-hoc command doesn’t know what roles are, so it needs the path to the source file to start with “roles/pi\_ddclient/files/”. However the role already knows the path to its files start that way.

Telling the role to find the file “roles/pi\_ddclient/files/etc/ddclient.conf” will make it look for the file “roles/pi\_ddclient/files/roles/pi\_ddclient/files/etc/ddclient.conf”, which probably doesn’t exist.

In your pd\_ddclient role’s tasks/main.yml file, try these “copy:” lines:

copy: src=etc/ddclient.conf dest=/etc/ddclient.conf owner=root group=root mode=0600 backup=yes  
copy: src=etc/default/ddclient dest=/etc/default/ddclient owner=root group=root mode=0600 backup=yes

---

<div class="post-metadata">

**Author:** ![Chris\_Short](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Short](https://forum.ansible.com/u/Chris_Short)\
**Post date:** [January 5, 2015, 12:38am UTC](https://forum.ansible.com/t/ad-hoc-works-playbook-works-wait-no-it-doesnt/17174/3 "2015-01-05T00:38:33Z")

</div>

It seems like you can’t have multiple copy/template operations under one name. I’m not sure if this is a YAML standard or an Ansible issue. I made these files into templates and split the template operations out under two names. Now it works. A little annoying but I did realize this was a limitation when dealing with some apache configs. Here is the tasks/main.yml file now:

---

<div class="post-metadata">

**Author:** ![vaida.dan](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@vaida.dan](https://forum.ansible.com/u/vaida.dan)\
**Post date:** [January 10, 2015, 6:35pm UTC](https://forum.ansible.com/t/ad-hoc-works-playbook-works-wait-no-it-doesnt/17174/4 "2015-01-10T18:35:35Z")

</div>

FWIW, the template module already knows where to look for the template files: templates/  
Same concept is true for other modules like copy which looks for the files in the files/ folder.  
Now, if you are willing to sacrifice the name of the task and make it a little bit more broad, you could use the template module with with\_items like so:

`
