ansible script to do remote execution of templates

Hi All,

I have a scenario where I need to execute ansible script which will run the templates on remote server. I have list of remote servers which when given to delegate_to is not working and fileglob is not copying the files to /tmp/copy rather folder creating a copy file.

Please help

  • hosts: 127.0.0.1
    connection: local
    tasks:

  • name: Install dependencies
    yum: name={{ item }} state=present
    with_items:

  • htop

  • git.x86_64

  • python-devel

  • name: Clone ansible repo on remote server
    git: repo=ssh://git@*****************************.git
    dest=/tmp
    version=feature/

    accept_hostkey=yes
    delegate_to: host1

  • name: Install config
    template:
    src: “{{ item }}”
    dest: “/tmp/copy”
    with_fileglob: “*”
    delegate_to: host1

The fileglob lookup, like ALL lookups
(https://docs.ansible.com/ansible/latest/plugins/lookup.html#lookup-plugins),
always runs on the controller

The template action plugin can ONLY use as source files on the
controller. https://docs.ansible.com/ansible/latest/modules/template_module.html#template-module
(see src option)

You either need to rung the git action with `delegate_to: localhost'
or syncronize the files from the remote before executing the template
action.