Yes template located on controller itself. We can it's getting the name "app1".
For template src only its getting error. Pls see variable instance_name got it's value as app1 in the result. Issue is only with src: TASK [test : Copy app1 file to /opt/conf.d/ Directory On Sun, 29 Mar, 2020, 1:32 PM Stefan Hornburg (Racke), <[email protected]> wrote: > On 3/29/20 9:52 AM, Geo P.C. wrote: > > Thanks Racke. > > > > Sorry it was my typo. Pls see my app.yml: > > > > > > - name: 'Copy {{ instance_name }} file to /opt/conf.d/ Directory' > > template: > > src: "{{ instance_name }}.conf.j2" > > dest: "/opt/{{ instance_name }}/conf.d/" > > owner: root > > group: root > > mode: 0644 > > > > In defaults main.yml defined vaiable as > > > > instance_name: 'app1' > > > > Please see the error I am getting: > > > > > > > > TASK [test : Copy app1 file to /opt/conf.d/ Directory] > > > ***************************************************************************************************************** > > fatal: [target1]: FAILED! => {"changed": false, "msg": "Could not find > or access 'app1.conf.j2'\nSearched > > > in:\n\t/mnt/d/Ansible/apache-playbook/roles/test/templates/app1.conf.j2\n\t/mnt/d/Ansible/apache-playbook/roles/test/app1.conf.j2\n\t/mnt/d/Ansible/apache-playbook/roles/test/tasks/templates/app1.conf.j2\n\t/mnt/d/Ansible/apache-playbook/roles/test/tasks/app1.conf.j2\n\t/mnt/d/Ansible/apache-playbook/templates/app1.conf.j2\n\t/mnt/d/Ansible/apache-playbook/app1.conf.j2 > > on the Ansible Controller.\nIf you are using a module and expect the > file to exist on the remote, see the remote_src > > option"} > > > > PLAY RECAP > > > ************************************************************************************************************************************************************* > > target1 : ok=2 changed=0 unreachable=0 > failed=1 skipped=0 rescued=0 ignored=0 > > > > Can you please help me on this. > > Where is your template located? It needs to be on the Ansible controller. > > Regards > Racke > > > > > > > On Sun, Mar 29, 2020 at 12:50 PM Stefan Hornburg (Racke) < > [email protected] <mailto:[email protected]>> wrote: > > > > 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: > ansible-project%[email protected]> > > <mailto:[email protected] <mailto: > ansible-project%[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] <mailto: > ansible-project%[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 > . > > > > -- > > 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/CAKtc8vVHcky9Yxa76e5rwSN%3D0b-rtj9d_cMtraDkUZYDToMYvw%40mail.gmail.com > > < > https://groups.google.com/d/msgid/ansible-project/CAKtc8vVHcky9Yxa76e5rwSN%3D0b-rtj9d_cMtraDkUZYDToMYvw%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/3c9fc58f-319d-2d90-eee6-4cf865ad743d%40linuxia.de > . > -- 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/CAKtc8vWO1PsjFmDHJ6J%3DZ2Ye8S8grYAjogja00M%2BXaRk7Js0Tg%40mail.gmail.com.
