Managing Jinja2 Templates Using Ansible

Hi Lakshmi,

Thank you very much…I followed what you suggested. It worked. How come using template is replacing correct value for inventory_hostname?

@Inderpreet I have the same issue.

image

@Dhanabalan

Copy module will copy the file from ‘files’ directory.
Template module will copy the jinja2 template from templates directory on Ansible playbooks.

1 Like

@Dhanabalan You should have used j2 extension for you template instead of js

jin

1 Like

Thank you, will try it if question repeat again.

@Inderpreet @Tej-Singh-Rana. I did the task as per the details . I did not check the permissions…Can you please reassign the task once. It was a silly mistake in permissions.

Hello, @pratikshag
Can you please share in the “Review Section” ?

Hello. Why my task is failed? “- ‘/var/www/html/index.html’ file has incorrect user owner on App Server 3”
In task was said nothing about the user owner. It was only about changing the rights to index.html (0744).

There is my scrennshots:

There is my task/main.yml code:

  • name: Add index.html
    template:
    src: /home/thor/ansible/role/httpd/templates/index.html.j2
    dest: /var/www/html/index.html
    mode: ‘0744’

There is part about index.html
c. Add a task inside <</home/thor/ansible/role/httpd/tasks/main.yml>> to copy this template on App Server 3 under <</var/www/html/index.html>>.
Also make sure that <</var/www/html/index.html>> file’s permissions are <<0744>>.