I would try and organize variables so they are associated with the host in 
inventory, rather than setting a lot of playbook vars

# ansible inventory (notice both hosts in a group called 'appservers' )

[appservers]

app_server_node1 appprops_file=node1-appprops.config
 app_server_node2 appprops_file=node2-appprops.config


*Playbook YML File (running by different user)*
---
- name: Test Template
  hosts: appservers

  tasks:
    - name: Copying the properties file
      copy:
        src: '/ConfigurationFolder/WrapperConfig/temp/{{appprops_file}}'
        dest: '/appserver/instance/conf/app_properties.conf'
        owner: app1
        group: app1
        mode: 0644

Ansible will put 
*/ConfigurationFolder/WrapperConfig/temp/*node1-appprops.config 
on node1 and */ConfigurationFolder/WrapperConfig/temp/*node2-appprops.config 
onto node2.  No need to use template as you can use the appprops_file 
variable which is different for each host.

Hope this helps,

Jon

On Sunday, July 26, 2020 at 8:34:07 PM UTC+1, [email protected] wrote:
>
> Hello Group,
>
> Requesting for advise or solution.
> The idea/objective is to have the specific filename to copy to the 
> specific node as the SRC path.
>
> *Filename*
> node1-appprops.config
> node2-appprops.config
>
> *Server Host*
> app_server_node1
> app_server_node2 
>
> *SRC Patch*
> /ConfigurationFolder/WrapperConfig/temp
>
> Someone says to use Jinja2 Template and I have created the file, 
> copy_appprops_node.j2. And, the j2 contains like...
>
> *J2 Template*
>
>
> *{% if ansible_hostname is match(" app*node1") %} 
> /ConfigurationFolder/WrapperConfig/temp/{{nodeID1}}- appprops.config {% 
> endif %}*
>
>
>
> *{% if ansible_hostname is match(" app*node2") %} 
> /ConfigurationFolder/WrapperConfig/temp/{{nodeID2}}- appprops.config {% 
> endif %}*
>
> *Playbook YML File (running by different user)*
> ---
> - name: Test Template
>   hosts: app_host
>   vars:
>     nodeID1: node1
>     nodeID2: node2
>
>   tasks:
>     - name: Copying the properties file
>       template:
>         src: copy_appprops_node.j2
>         dest: "/appserver/instance/conf/app_properties.conf"
>         owner: app1
>         group: app1
>         mode: 0644
> ...
> # ansible inventory (notice both hosts in a group called 'appservers' )
>
> *[appservers]*
> app_server_node1 appprops_file=node1-appprops.config
> app_server_node2 appprops_file=node2-appprops.config
> Any help and assistance would be highly appreciated.
> Or, any idea that will work from the objective.
>
> Thank you in advance.
>
> Cheers....
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/7503f84c-f8f3-4aab-bd97-40e35ab36b7ao%40googlegroups.com.

Reply via email to