Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

How to use template in Ansible?

How to use template in Ansible?

##### Step 1 – Create your inventory file with #####

[code]$ vi inventory
35.154.85.120 ansible_user=root ansible_ssh_private_key_file=remote.pem
35.154.85.120 ansible_user=root ansible_ssh_private_key_file=remote.pem[/code]

##### Step 2 – Create templates directory #####

[code]$ mkdir templates
$ vi templates/index.j2

<!DOCTYPE html>
<html>
<body>
<h1> Welcome to DevOpsSchool.com Ansible Training</h1>
<h3> This is Deployed in OS Family – {{ ansible_os_family }} </h3>
<h3> This is Deployed in OS Family – {{ ansible_hostname }} </h3>
<h3> Company Name – {{ companyname }} </h3>
companyname

</body>
</html>[/code]

<strong>##### Step 3 – Create a playbook.yaml#####</strong>

[code]—
– name: This sets up an httpd webserver
hosts: all
remote_user: ec2-user
become: yes
vars:
ansible_ssh_private_key_file: remote.pem
companyname: DevOpsSchool.com
pack: httpd
tasks:
– name: Install the httpd apps
yum: name={{ pack }}
– name: Deploy configuration File
template: src=templates/index.j2 dest=/var/www/html/index.html
– name: start the httpd service
service: name={{ pack }} state=started[/code]

##### Step 4 – Last comamds to execute #####

[code]$ ansible-playbook -i inventory httpd.yaml[/code]

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x