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]
- Top 10 Website Development Companies in Ludhiana - December 5, 2024
- Exploring Career Options: Why Trade Schools Are a Great Alternative - December 5, 2024
- Announcing the Launch of DevOpsSchool.jp Services in Japan: Transforming IT Operations in Tokyo and Beyond - December 3, 2024