demo with templates
This commit is contained in:
33
README.md
33
README.md
@@ -33,7 +33,7 @@ Red Hat Certified Specialist in Ansible Automation (EX407) Preparation Course
|
||||
- [LAB: Ansible Playbooks - Error Handling](#lab-ansible-playbooks---error-handling)
|
||||
- [Create and Use Templates to Create Customized Configuration Files](#create-and-use-templates-to-create-customized-configuration-files)
|
||||
- [Using Ansible Templates Lecture](#using-ansible-templates-lecture)
|
||||
|
||||
- [Demo: Using Ansible Templates](#demo-using-ansible-templates)
|
||||
|
||||
|
||||
## Understanding Core Components of Ansible
|
||||
@@ -939,4 +939,35 @@ Template Module
|
||||
Template File
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
### Demo: Using Ansible Templates
|
||||
|
||||
Our template `network.j2` file will look like this:
|
||||
```
|
||||
My IP address is {{ ansible_default_ipv4.address }}.
|
||||
|
||||
{{ ansible_distribution }} is my OS version.
|
||||
```
|
||||
|
||||
- `ansible_default_ipv4.address` and `ansible_distribution` - are gathered facts during playbook run
|
||||
|
||||
Cookbook for calling our template will look like this:
|
||||
```
|
||||
---
|
||||
- hosts: labservers
|
||||
tasks:
|
||||
- name: deploy local net file
|
||||
template:
|
||||
src: /home/cloud_user/template/network.j2
|
||||
dest: /home/cloud_user/template/network.txt
|
||||
```
|
||||
|
||||
Created file `/home/cloud_user/template/network.txt` after playbook run will be:
|
||||
```
|
||||
My IP address is 142.21.46.232.
|
||||
|
||||
RedHat is my OS version.
|
||||
```
|
||||
|
||||
|
||||
7
playbooks/network_playbook.yml
Normal file
7
playbooks/network_playbook.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
- hosts: labservers
|
||||
tasks:
|
||||
- name: deploy local net file
|
||||
template:
|
||||
src: /home/cloud_user/template/network.j2
|
||||
dest: /home/cloud_user/template/network.txt
|
||||
3
templates/network.j2
Normal file
3
templates/network.j2
Normal file
@@ -0,0 +1,3 @@
|
||||
My IP address is {{ ansible_default_ipv4.address }}.
|
||||
|
||||
{{ ansible_distribution }} is my OS version.
|
||||
Reference in New Issue
Block a user