Re: [ansible-project] remote_src and template_host for template module not working for me

1,505 views
Skip to first unread message
Message has been deleted

Dick Visser

unread,
Feb 19, 2020, 9:23:36 AM2/19/20
to ansible...@googlegroups.com
On Wed, 19 Feb 2020 at 15:13, Janmejaya Swain <janmeja...@gmail.com> wrote:
>
> Hi ,
>
> Can any one please help on this, which is very appreciable. .
>
> ---
> - hosts: all
> remote_user: root
> vars_files:
> - json/UAT.json
>
> tasks:
> - name: Generate configGen files
> template:
> src: /template/test.j2
> dest: /properties/test.properties
> remote_src: yes
> template_host: < host ip >
>
>
> Error:
>
> ERROR! vars file /template/test.j2 was not found
>
> 15
>
> Could not find file on the Ansible Controller.
>
> 16
>
> If you are using a module and expect the file to exist on the remote, see the remote_src option
>
>
> In same way it showing it showing json/UAT.json was not found.
>
>
> NOTE: Can you please help on it and we are using ansible 2.9.


A few issues:

1. The file /template/test.j2 needs to be available on the remote
node, because you specified "remote_src: yes". Fix this.
2. template_host is not a valid parameter for the template task - and
it is not clear what you expect this to do.
3. There appears to be no problem with the vars file json/UAT.json -
contrary to what you think.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT
Message has been deleted

Jordan Borean

unread,
Feb 20, 2020, 3:09:23 AM2/20/20
to Ansible Project
You can’t, template will only work with a source on the controller as that is where the cars are stored. Either store the template in your role/playbook or use fetch to fetch the file to the controller temporarily and then template it from there.

Dick Visser

unread,
Feb 20, 2020, 4:52:18 AM2/20/20
to ansible...@googlegroups.com
As jbor...@gmail.com said the template module does NOT have a
remote_src paramater.
I mixed things up with the file module, which does have that.

A scenario whereby both the template src and destination are on the
remote node is only possible by fetching the template in an
intermediate step.

I remember having tried to combine slurp with copy+remote_src but that
didn't work.
Message has been deleted
Message has been deleted

Stefan Hornburg (Racke)

unread,
Feb 25, 2020, 8:12:31 AM2/25/20
to ansible...@googlegroups.com
On 2/25/20 1:56 PM, Janmejaya Swain wrote:
> Thank u Jordan and Dick , 
>
> Can you please help to know , how can we fetch folder from remote to controller as fetch module not supported folders
> rather than files. 
> i  can able   to fetch  multiple files but not able to fetch folders .
>

Try the synchronize module in pull mode.

Regards
Racke

>
> On Wednesday, February 19, 2020 at 7:42:56 PM UTC+5:30, Janmejaya Swain wrote:
>
> Hi ,
>
> Can any one please  help on this, which is very appreciable.  .
>
> ---
>  - hosts: all
>    remote_user: root
>    vars_files:
>           - json/UAT.json
>
>    tasks:
>      - name: Generate configGen files 
>        template:
>          src: /template/test.j2
>          dest: /properties/test.properties
>          remote_src: yes
>          template_host: < host ip >
>       
>
> Error:
>
> ERROR! vars file /template/test.j2 was not found
>
> 15
>
> Could not find file on the Ansible Controller.
>
> 16
>
> If you are using a module and expect the file to exist on the remote, see the remote_src option
>
>
> In same way it showing it showing json/UAT.json was not found.
>
>
> NOTE: Can you please help on it and we are using ansible 2.9. 
>
> --
> 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
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/6bbf2b3b-d489-423d-bde2-3211e12be389%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/6bbf2b3b-d489-423d-bde2-3211e12be389%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc
Message has been deleted

Stefan Hornburg (Racke)

unread,
Feb 25, 2020, 9:53:37 AM2/25/20
to ansible...@googlegroups.com
On 2/25/20 3:49 PM, Janmejaya Swain wrote:
> Thanks Racke , its work for me 
>

Well if you don't mind please post your resulting task so other list members can see how you use synchronize.

Simply stating "it doesn't work" or "it works for me" without a task to refer to doesn't really work for *me* :-)

Regards
Racke
> > ansible...@googlegroups.com <javascript:> <mailto:ansible-proje...@googlegroups.com <javascript:>>.
> <https://groups.google.com/d/msgid/ansible-project/6bbf2b3b-d489-423d-bde2-3211e12be389%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/6bbf2b3b-d489-423d-bde2-3211e12be389%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
> --
> 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
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/715b5bed-6591-422d-b43f-3c979122bb20%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/715b5bed-6591-422d-b43f-3c979122bb20%40googlegroups.com?utm_medium=email&utm_source=footer>.
signature.asc
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Stefan Hornburg (Racke)

unread,
Feb 26, 2020, 3:51:00 AM2/26/20
to ansible...@googlegroups.com
On 2/26/20 8:24 AM, Janmejaya Swain wrote:
> Hi , 
>
> 1. I have multiple json as well as j2 files , Need to generate multiple config files by using template module. 
> 2.  In fetch module . fetch the files with including host name in path . How we can avoid this hostname in path ?
>      Ex: 
> - name: fetch tar file from remote to local machine 
>     fetch:
>         src: /tmp/tts_config.tar
>         dest: /tmp/
>         flat: ture
>
> and files are present in following path in controller 
> /tmp/namwrncld1135.nam.nsroot.net/tmp/tts_config.tar
> namwrncld1135.nam.nsroot.net is remote machine 
> Can anyone please  help here. so that i greatfull to u .
>
> Thanks 
>

It eludes me why you don't install rsync on the Ansible controller and use synchronize module as recommended.
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/e1d10a4c-dcaa-48af-92ef-25a1504e56c3%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/e1d10a4c-dcaa-48af-92ef-25a1504e56c3%40googlegroups.com?utm_medium=email&utm_source=footer>.
signature.asc

Vladimir Botka

unread,
Feb 26, 2020, 4:12:31 AM2/26/20
to Janmejaya Swain, ansible...@googlegroups.com
On Tue, 25 Feb 2020 23:24:14 -0800 (PST)
Janmejaya Swain <janmeja...@gmail.com> wrote:

> 2. In fetch module . fetch the files with including host name in path .
> How we can avoid this hostname in path ?
>
> - name: fetch tar file from remote to local machine
> fetch:
> src: /tmp/tts_config.tar
> dest: /tmp/
> flat: ture

Fix the truthy. See
https://docs.ansible.com/ansible/latest/modules/fetch_module.html#parameters

flat: true

HTH,

-vlado
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages