Found the solution for copying a file from Ansible Tower server to a remote
server when the Play is delegated to Tower server.
---
- name: Copy file to remote server
gather_facts: no
hosts: 127.0.0.1
tasks:
- set_fact:
jsonVariable: "{{ lookup('file', '/tmp/myfile.json') }}"
cacheable: true
- name: Create empty file on remote server
file:
path: "{{ item }}"
state: touch
mode: 0750
delegate_to: remoteServer
with_items:
- /opt/json/myfile.json
- name: Copy file to remote server
lineinfile:
dest: /opt/json/myfile.json
line: "{{ jsonVariable }}"
insertafter: EOF
delegate_to: remoteServer
On Tuesday, 20 November 2018 07:33:57 UTC-5, Saravanan wrote:
>
> Hi Jon,
> The file is exist on Ansible tower server and able to lookup file, attach
> to email. However, using copy module, unable to copy this file from Ansible
> Tower server to remote server path.
>
> - hosts: remoteserver
> tasks:
> - name: Ansible copy file to remote server
> copy:
> src: /tmp/somefile.txt
> dest: /opt/remote/server/path
>
>
> Getting strange error. saying unable to find src file. On the other hand
> able to lookup file and attach to email.
>
>
> On Monday, 19 November 2018 16:35:53 UTC-5, Jonathan Lozada De La Matta
> wrote:
>>
>> do you have the file in all the nodes?
>>
>> On Mon, Nov 19, 2018 at 4:25 PM Saravanan <[email protected]> wrote:
>>
>>> I am getting source not found error while copying a file from Ansible
>>> Tower server to remote server. Actually file is available in the local path
>>> of Ansible Tower server. Any help is much appreciated.
>>>
>>> On Monday, 19 November 2018 09:15:39 UTC-5, Saravanan wrote:
>>>>
>>>> Hi Ansible Experts,
>>>> Need to copy a file from Ansible tower server to remote server using
>>>> copy module. Can you please help to achieve this using copy module or any
>>>> other module in Ansible?
>>>>
>>>> ---
>>>> - name: Copy file to remote server
>>>> gather_facts: no
>>>> hosts: 127.0.0.1
>>>>
>>>> tasks:
>>>>
>>>> - name: Copy JSON file to remote server
>>>> copy:
>>>> dest: /apps/web/scripts/json
>>>> src: /tmp/report.json
>>>> remote_src: no
>>>> owner: user
>>>> group: group
>>>> mode: 0644
>>>> delegate_to: remote_server
>>>> become_user: awx
>>>> become: no
>>>>
>>>>
>>>>
>>>>
>>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Ansible Project" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> To post to this group, send email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/993a7441-8ea0-4181-9e87-4bfb715876ea%40googlegroups.com
>>>
>>> <https://groups.google.com/d/msgid/ansible-project/993a7441-8ea0-4181-9e87-4bfb715876ea%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>> --
>>
>> Jonathan lozada de la matta
>>
>> AUTOMATION PRACTICE
>>
>>
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/628ac108-a3fe-4aee-b2b5-407f1722b179%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.