Ansible# 14 - Variables and their Scopes in Ansible Playbook - Ansible Facts and Module setup

  Рет қаралды 307

DevLinux

DevLinux

Күн бұрын

In our video# 6 [ • Ansible# 6 - How to Ga... ] we discussed how to use the Ansible Facts and the related module named "setup" to gather a number of details about our Ansible environment and systems.
In this lab exercise, we discuss how to define and use Ansible's inbuilt variables or system variables, and also discuss how to create our own variables from scratch.
We understand the different scopes of variables declared at different levels in a playbook.
We begin with a simple playbook with some builtin Ansible variables and add on to it some comlex logic while keeping things easy to understand and grasp.
I am sharing with you the finished Playbook here "as it is" without any guarantee for it to work on your system. You first need to understand the concepts discussed and explained in this video. Then, you should be using the code shared here:
Start of the Playbook
---
- name: Play# 1 - Playing with Ansible Variables - Inbuilt and User Defined Variables
hosts: docker
gather_facts: yes
vars:
- greetings: "W E L C O M E"
- error_msg: "Specify the custom variable - whoami"
tasks:
- name: Show System Information
debug:
msg: "OS Info - {{ ansible_system }}"
- name: Show Hostname as found in Ansible Facts
debug:
msg: "Hostname - {{ ansible_hostname }}"
- name: Show Hostname as found in the Inventory File
debug:
msg: "Hostname - {{ inventory_hostname }}"
- name: Show Error / Help Message
debug:
msg: "{{ error_msg }}"
when: whoami is not defined
- name: Redefining the varialbe - greetings
vars:
- greetings: "Hello, there!"
- whoami: "I have no idea who the hell I am!"
debug:
msg: "Greetings - {{ greetings }} / {{ whoami }}"
- name: Show Greetings
debug: msg={{ greetings }}
- name: Show who you are?
debug: msg={{ whoami }}
when: whoami is defined
- name: Play# 2 - Playing with Ansible Variables - Inbuilt and User Defined Variables
hosts: web
gather_facts: no
tasks:
- name: Show Inventory Hostname
debug:
msg: "Hostname - {{ inventory_hostname }}"
- name: Show Who are you?
debug: msg={{ whoami }}
...
# End of the Playbook

Пікірлер
Фейковый воришка 😂
00:51
КАРЕНА МАКАРЕНА
Рет қаралды 7 МЛН
Остановили аттракцион из-за дочки!
00:42
Victoria Portfolio
Рет қаралды 3,1 МЛН
Bike Vs Tricycle Fast Challenge
00:43
Russo
Рет қаралды 19 МЛН
Фейковый воришка 😂
00:51
КАРЕНА МАКАРЕНА
Рет қаралды 7 МЛН