On 3/29/20 9:14 AM, Geo P.C. wrote:
>
> In ansible we are trying to access different templates based on variable.
>
> We have following template files like:
>
> templates
> app1.conf.j2
> app2.conf.j2
> app3.conf.j2
>
> taks
> app.yml
>
>
> In tasks we need to copy template file based on the app name. for eg: we will
> specify a variable named "instance_name"
> to either app1 or app2 or app3.
>
> Now based on the variable we need to copy the app file to /opt/((
> instance_name }}/conf.d/.
>
> we created ansbile task as follows but its not working.
>
>
> - name: 'Copy {{ instance_name }} file to /opt/conf.d/ Directory'
> template:
> src: "{{ instance_name }}"
> dest: "/opt/{{ instance_name }}/conf.d/"
> owner: root
> group: root
> mode: 0644
>
>
> When we hard code "src" to app1.conf.j2 its working for app1.
You don't give any details how your task fails, but I would guess you need to
say:
src: "{{ instance_name }}.conf.j2"
Regards
Racke
>
> Please let us know is it possible with this method? We are having around 20
> apps and whats the best method to simplify
> the ansible playbook to specify only the variable.
>
> Thanks & Regards
> Geo
>
> --
> 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]
> <mailto:[email protected]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAKtc8vWncufK%3DvO%3DEpRCUr_MavBAzT_wSWURXybW7b3r-BO_UA%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAKtc8vWncufK%3DvO%3DEpRCUr_MavBAzT_wSWURXybW7b3r-BO_UA%40mail.gmail.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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/944bd884-7913-6132-f20a-801d3b52483f%40linuxia.de.
signature.asc
Description: OpenPGP digital signature
