Friday, April 17, 2026

YAML_Ansible_1

 Binary Data


binary data
In YAML, binary data is used to store: 👉 Non-text data (images, files, certificates, keys, etc.). Since YAML is text-based, binary data is encoded using: 👉 Base64 encoding

Binary data can be represented in YAML using Base64 encoding. This allows you to include binary data, such as images or files, within a YAML document.
converted → Base64 → stored as text

Srtucture:
file_content: !!binary |
SGVsbG8gRGV2T3Bz

file_data: !!binary |
R0lGODlhAQABAIAAAAUEBAgKACwAAAAAAAAQABAAACAkQBADs=
What happens internally:
Original data → Hello DevOps
Encoded → SGVsbG8gRGV2T3Bz
YAML stores → text safely

eg
certificate: !!binary |
MIIDdzCCAl+gAwIBAgIEbM2Q0jANBgkqhkiG9w0BAQsFADBoMQswCQYDVQQG
EwJVUzELMAkGA1UECBMCQ0ExETAPBgNVBAcTCFNhbiBKb3NlMRgwFgYDVQQK
EwwgRXhhbXBsZSBDb3JwMQ8wDQYDVQQLEwZJVCBEZXB0MRgwFgYDVQQDEw9l
eGFtcGxlLmNvbTAeFw0yMTA1MDkwODI4NDJaFw0zMTA1MDcwODI4NDJaMGgx
CzAJBgNVBAYTAlVTMQswCQYDVQQIEwJDQTERMA8GA1UEBxMIU2FuIEpvc2Ux
GDAWBgNVBAoTD0V4YW1wbGUgQ29ycDEPMA0GA1UECxMGSUQgRGVwdDEYMBYG
A1UEAxMPZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
AoIBAQC7mLhHjZyqfXlH65s8v1Z9Xy+5n2u7v1z9X9X9X9X9X9X9X9X9X9X9X

apiVersion: v1
kind: Secret
data:
username: YWRtaW4=
password: cGFzc3dvcmQ=
to Decode Base64
Base64 → Decoded data

# echo "password" | base64
# cGFzc3dvcmQ=
# echo cGFzc3dvcmQ= | base64 --decode
# password
# echo cGFzc3dvcmQ= | base64 -d
# password

YAML decodes the Base64 encoded data back to its original form when it is read or processed.

yaml_Ansible

 YAML Data Types


YAML organizes data using three basic data types: scalars, sequences, and maps. Each of these data types has its own syntax and structure.

1. Scalars
A scalar is a single value, such as a string, number, or boolean. Scalars can be represented in various ways in YAML, including plain style, double-quoted style, and single-quoted style.
name: Alagarasan
age: 30
is_devops_consultant: true
In the above example, name is a string scalar, age is a numeric scalar, and is_devops_consultant is a boolean scalar.

Key value
key: value
key = name
: = Seprator. # Space after colon is mandatory
value = data


String
Text values (quoted or unquoted)
name: Alagarasan
role: "DevOps Engineer"
company: 'TCS'

Integer (Number)
Numeric values without a decimal point (whole numbers)
age: 30
experience: 8

Float (Number)
Numeric values with a decimal point (floating-point numbers)
cpu_usage: 75.5
version: 1.2

Boolean
True or false values
is_active: true
is_admin: false

Null (Empty value)
null is not a string, It represents absence of value
Null (Empty value)
null means:👉 No value / empty value / nothing assigned
~ is a shorthand for null in YAML. It represents the absence of a value, similar to null in other programming languages. When you see ~ in a YAML file, it indicates that the value is intentionally left empty or not assigned.
value1: null
value2: Null
value3: NULL
value4: ~
value5:

eg
user:
name: Alagarasan
middle_name: null
nickname: ~
age: 30
is_active: true




NAN (Not a Number)
NaN stands for: Not a Number. It is a special floating-point value that represents an undefined or unrepresentable value, such as the result of dividing zero by zero.
result: .nan
result: .NaN
result: .NAN

eg
metrics:
cpu_usage: 75.5
memory_usage: .nan
👉 Here:
cpu_usage → valid number
memory_usage → undefined / not measurable


.infinite (INF)
INF stands for: Infinity. It is a special floating-point value that represents an infinitely large number
positive_infinity: .inf
negative_infinity: -.inf
also_positive_infinity: .INF
also_negative_infinity: -.INF

Positive vs Negative Infinity

positive: .inf
negative: -.inf

👉 Meaning:
.inf → +∞
-.inf → −∞

Tuesday, April 14, 2026

yaml


YAML
YAML (YAML Ain’t Markup Language) is a human-readable data format.

Supports 2 tpype of extension
<file_name>.yaml
<file_name>.yml

yaml is case sensitive. So we have to be careful while writing the yaml file. We have to use the same case for the keys and values.

yaml is not a programming language, it is a data serialization language. It is used to represent data in a structured format. It is commonly used for configuration files, data exchange between languages with different data structures, and for storing data in a human-readable format.

yaml is a superset of JSON, which means that any valid JSON file is also a valid YAML file. However, YAML has additional features that make it more powerful and flexible than JSON.

Friday, April 10, 2026

Ansible_7

 Variables

Variables can be used in tasks, as well as in template files. we can call variables by "{{ var_name }}"

Quoting in Ansible Strings
A variable right after specifying the module, the YAML parser will misinterpret the variable reference as the beginning of an inline dictionary.


- name: Perform some task
command: {{ myapp }} -a foo

Ansible will try to parse the first part of {{ myapp }} -a foo as a dictionary instead of a string, and will return an error. In this case, you must quote the arguments:
- name: Perform some task
command: "{{ myapp }} -a foo"

A similar problem arises if your argument contains a colon. For example:
- name: Show a debug message
debug:
msg: The debug module will print a message: neat, eh?

The colon in the msg argument trips up the YAML parser.

To get around this, you need to quote the entire msg string. Single and double quotes are both correct; Bas prefers to use double quotes when the string has variables:
- name: Show a debug message
debug:
msg: "The debug module will print a message: neat, eh?"

This will make the YAML parser happy. Ansible supports alternating single and double quotes,
'single quotes' → literal strings
"double quotes" → interpreted strings (supports escaping + special chars)

Double Quotes
- name: Print variable
debug:
msg: "Hello {{ user }}"
👉 {{ user }} will be evaluated

msg: "Line1\nLine2"
👉 Produces:
Line1
Line2


Single Quotes
- name: Print variable
debug:
msg: 'Hello {{ user }}'
👉 Jinja2 still processes it, BUT:
Escaping behaves differently
Harder to nest quotes

msg: 'Line1\nLine2'
👉 Produces:
Line1\nLine2

Loop
A loop executes the task multiple times, each time replacing item with different values from the specified list:
- name: Install multiple packages
hosts: all
tasks:
- name: Install packages
yum:
name: "{{ item }}"
state: present
loop:
- nginx
- git
- curl

Loop with List Variable
vars:
packages:
- nginx
- git
- curl

tasks:
- name: Install packages
yum:
name: "{{ item }}"
state: present
loop: "{{ packages }}"

Loop with Dictionary (Key-Value)
vars:
users:
user1: dev
user2: admin

tasks:
- name: Create users
user:
name: "{{ item.key }}"
comment: "{{ item.value }}"
loop: "{{ users | dict2items }}"
👉 dict2items converts dictionary → list