# module (copy) is missing interpreter line

**URL:** <https://forum.ansible.com/t/module-copy-is-missing-interpreter-line/21933>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [July 6, 2016, 2:14pm UTC](https://forum.ansible.com/t/module-copy-is-missing-interpreter-line/21933 "2016-07-06T14:14:05Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![actionmystique](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/actionmystique/32/1678_2.png) [@actionmystique](https://forum.ansible.com/u/actionmystique)\
**Post date:** [July 6, 2016, 2:14pm UTC](https://forum.ansible.com/t/module-copy-is-missing-interpreter-line/21933/1 "2016-07-06T14:14:05Z")

</div>

Hello everyone,

It seems quite difficult to perform a very simple task: save the content of a variable to a file.  
This variable content is not just a string, but several lines as shown by the debug module:

“out.stdout\_lines”: [  
[  
“Using 2011 out of 262144 bytes, uncompressed size = 3870 bytes”,  
“!”,  
“! Last configuration change at 18:34:42 UTC Thu Jun 30 2016 by admin”,  
“!”,  
“version 15.2”,  
…  
“hostname IOSv\_L2\_1”,  
…  
“end”,  
“”  
]  
]

Trying to use the “copy” module leads to the previously mentioned issue:

- name: Copying config into local file  
copy:  
content: “{{ out.stdout\_lines }}”  
dest: host\_vars/{{ inventory\_hostname }}/{{ inventory\_hostname }}\_{{ config }}.txt

=\>

TASK [ios\_pull\_config : Copying config into local file] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/actionmystique/Program-Files/Ubuntu/Ansible/git-Ansible/roles/ios\_pull\_config/tasks/main.yml:59  
\<192.168.137.242\> ESTABLISH LOCAL CONNECTION FOR USER: root  
\<192.168.137.242\> EXEC /bin/sh -c ‘( umask 77 && mkdir -p “`echo $HOME/.ansible/tmp/ansible-tmp-1467812828.82-260068933148720`” && echo ansible-tmp-1467812828.82-260068933148720=“`echo $HOME/.ansible/tmp/ansible-tmp-1467812828.82-260068933148720`” ) && sleep 0’  
\<192.168.137.242\> PUT /tmp/tmpotKrzg TO /root/.ansible/tmp/ansible-tmp-1467812828.82-260068933148720/stat  
\<192.168.137.242\> EXEC /bin/sh -c ‘LANG=en\_US.UTF-8 LC\_ALL=en\_US.UTF-8 LC\_MESSAGES=en\_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1467812828.82-260068933148720/stat; rm -rf “/root/.ansible/tmp/ansible-tmp-1467812828.82-260068933148720/” \> /dev/null 2\>&1 && sleep 0’  
\<192.168.137.242\> EXEC /bin/sh -c ‘( umask 77 && mkdir -p “`echo $HOME/.ansible/tmp/ansible-tmp-1467812828.91-263479362702141`” && echo ansible-tmp-1467812828.91-263479362702141=“`echo $HOME/.ansible/tmp/ansible-tmp-1467812828.91-263479362702141`” ) && sleep 0’  
\<192.168.137.242\> PUT /tmp/tmp5gr0LH TO /root/.ansible/tmp/ansible-tmp-1467812828.91-263479362702141/source  
fatal: [192.168.137.242]: FAILED! =\> {“failed”: true, “msg”: “**module (copy) is missing interpreter line**”}

In /etc/ansible/ansible.cfg with ansible 2.1.1.0, the default library path is defined:  
library = /usr/lib/python2.7/dist-packages/ansible

Also, there are 2 default “copy.py” in the downstream tree:

- ./modules/core/files/copy.py
- ./plugins/action/copy.py  
Isn’t this confusing for Ansible?

---

<div class="post-metadata">

**Author:** ![actionmystique](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/actionmystique/32/1678_2.png) [@actionmystique](https://forum.ansible.com/u/actionmystique)\
**Post date:** [July 6, 2016, 2:27pm UTC](https://forum.ansible.com/t/module-copy-is-missing-interpreter-line/21933/2 "2016-07-06T14:27:47Z")

</div>

How do we know that Ansible uses its module and not python’s own “copy.py” available in:

/usr/lib/python3.5/copy.py  
/usr/lib/python2.7/copy.py

---

<div class="post-metadata">

**Author:** ![actionmystique](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/actionmystique/32/1678_2.png) [@actionmystique](https://forum.ansible.com/u/actionmystique)\
**Post date:** [July 6, 2016, 5:15pm UTC](https://forum.ansible.com/t/module-copy-is-missing-interpreter-line/21933/3 "2016-07-06T17:15:53Z")

</div>

Exactly same issue if I slightly modify the call in the role with:

- name: Saving config into local file  
local\_action:  
copy content=“{{ out.stdout\_lines }}” dest=host\_vars/“{{ inventory\_hostname }}”/“{{ inventory\_hostname }}”\_“{{ config }}”.txt

Also, I haven’t mentioned the fact that I do not experience that issue with other modules.

---

<div class="post-metadata">

**Author:** ![actionmystique](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/actionmystique/32/1678_2.png) [@actionmystique](https://forum.ansible.com/u/actionmystique)\
**Post date:** [July 6, 2016, 5:24pm UTC](https://forum.ansible.com/t/module-copy-is-missing-interpreter-line/21933/4 "2016-07-06T17:24:46Z")

</div>

Also, downgrading from 2.1.1.0 (which is a RC) to stable 2.1.0 does not change anything as far as this issue is concerned.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 7, 2016, 1:29pm UTC](https://forum.ansible.com/t/module-copy-is-missing-interpreter-line/21933/5 "2016-07-07T13:29:38Z")

</div>

The copy module is not design for this, use the template module instead.

---

<div class="post-metadata">

**Author:** ![actionmystique](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/actionmystique/32/1678_2.png) [@actionmystique](https://forum.ansible.com/u/actionmystique)\
**Post date:** [July 7, 2016, 3:02pm UTC](https://forum.ansible.com/t/module-copy-is-missing-interpreter-line/21933/6 "2016-07-07T15:02:42Z")

</div>

No: the template module only deals with files, not with a variable.

---

<div class="post-metadata">

**Author:** ![actionmystique](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/actionmystique/32/1678_2.png) [@actionmystique](https://forum.ansible.com/u/actionmystique)\
**Post date:** [July 7, 2016, 3:14pm UTC](https://forum.ansible.com/t/module-copy-is-missing-interpreter-line/21933/7 "2016-07-07T15:14:10Z")

</div>

If you are referring to [“ios\_template”](http://docs.ansible.com/ansible/ios_template_module.html), the module is designed to push a running-config, not to pull it from the remote device.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 7, 2016, 3:59pm UTC](https://forum.ansible.com/t/module-copy-is-missing-interpreter-line/21933/8 "2016-07-07T15:59:40Z")

</div>

Yes, the template module, in your first post you write "save the content of a variable to a file" that is exactly what the template module is highly capable of doing  
[https://docs.ansible.com/ansible/template\_module.html](https://docs.ansible.com/ansible/template_module.html)

The template will be Jinja2 code looping the variable and write the content to a file.

---

<div class="post-metadata">

**Author:** ![actionmystique](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/actionmystique/32/1678_2.png) [@actionmystique](https://forum.ansible.com/u/actionmystique)\
**Post date:** [July 7, 2016, 4:43pm UTC](https://forum.ansible.com/t/module-copy-is-missing-interpreter-line/21933/9 "2016-07-07T16:43:44Z")

</div>

I combined my posts #2 & #3, and it worked!  
That is to say, downgrading to 2.1.0 & using “local\_action: copy…” enables me to save the content of the variable into a local file.

However, the file is barely readable because all line feeds have been removed and each line is enclosed by “”, but at least that’s a start.  
That means some formatting is necessary, unless another way exists.

---

<div class="post-metadata">

**Author:** ![actionmystique](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/actionmystique/32/1678_2.png) [@actionmystique](https://forum.ansible.com/u/actionmystique)\
**Post date:** [July 8, 2016, 5:28pm UTC](https://forum.ansible.com/t/module-copy-is-missing-interpreter-line/21933/10 "2016-07-08T17:28:20Z")

</div>

I’ve just tried with 2.1.1.0 RC2 and it works. As a conclusion, and since there is a typo in my first post, here is one **solution** :

- name: Saving config into local file  
local\_action:  
copy content=“{{ out.stdout }}” dest=files/configs/{{ inventory\_hostname }}/{{ inventory\_hostname }}_{{ config }}_{{ ansible\_date\_time.date }}_{{ ansible\_date\_time.time }}_{{ ansible\_date\_time.tz }}.txt

- name: Reformatting config file  
local\_action:  
script {{ role\_path }}/…/…/files/scripts/format-config.sh files/configs/{{ inventory\_hostname }}/{{ inventory\_hostname }}_{{ config }}_{{ ansible\_date\_time.date }}_{{ ansible\_date\_time.time }}_{{ ansible\_date\_time.tz }}.txt
