Friday, April 24, 2026

yaml_Ansible_6

 yaml tags

In YAML, tags are a way to explicitly define the data type of a value. 

Normally YAML auto-detects types (like string, int, boolean), but tags let you override or clarify that behavior.



Basic Syntax of YAML Tags

Tags are written using !! before a value:


Integer $ count: !!int 10

Float $ count: !!int 10

boolean $ enabled: !!bool yes

Null $ value: !!null null

String $ name: !!str 12345

yaml_Ansible_5

 Date and Timestamps in yaml


YYYY-MM-DD #standard date format 

YYYY-MM-DDTHH:MM:SSZ  # Full Timestamps

T = Seprates Date and Timestamps

Z = for UTC Timestamps


iso8601 format

YYYY-MM-DDTHH:MM:SS+(OR)-HH:MM (The offset timezone (-5))

Ansible_9 Automation Execution Environment (EE)

 An Automation Execution Environment (EE) is a portable, consistent runtime for running Ansible automation. Think of it as a pre-built container image (like Docker/Podman) that already has everything your automation needs.


🔹 Simple Idea
Instead of installing Python, Ansible, collections, and dependencies on every control node, you package everything into one environment and run it anywhere.


Ansible execution environments (EE) were introduced in Ansible Automation Platform 2 to provide a defined, consistent and portable environment for executing automation jobs.
Execution environments are basically Linux container images that help execute Ansible playbooks.

The container images for the execution environments contain the necessary components to execute Ansible automation jobs. These include Python, Ansible (ansible-core), Ansible Runner, required Python libraries, and dependencies.

When you install Ansible Automation Platform, the installer deploys the following container images whether you're in a connected or an unconnected installation:

* The ee-29-rhel8 image contains Ansible 2.9 to use with older Ansible playbooks.
* ee-minimal-rhel8 is the minimal container image with ansible-core and basic collections.
* ee-supported-rhel8 is the container image with ansible-core and automation content collections supported by Red Hat.

Ansible Automation Platform's default container images let you start doing automation without any additional configurations.

You can follow the standard container image build process for building execution environment container images, but Ansible Automation Platform also includes a command-line utility called ansible-builder to build container images for custom execution environments.

The ansible-builder tool can be installed from the upstream Python repository or the Red Hat RPM repository:

## Install ansible-builder utility
$ pip3 install ansible-builder

## Ansible Automation Platform repository subscription is required
$ sudo dnf install ansible-builder

The ansible-builder helps you build container images with the definition file execution-environment.yml.

A typical execution-environment.yml contains the base container image (EE_BASE_IMAGE), ansible.cfg, and other dependency file details:
---
version: 1
build_arg_defaults:
EE_BASE_IMAGE: 'registry.redhat.io/ee-minimal-rhel8:latest'
ansible_config: 'ansible.cfg'
dependencies:
galaxy: requirements.yml
python: requirements.txt
additional_build_steps:
append:
- RUN microdnf install which


Once you've prepared the execution-environment.yml, execute the ansible-builder build command to create a build context that includes the Containerfile.
$ ansible-builder build --tag my_custom_ee
Running command:
podman build -f context/Containerfile -t my_custom_ee context
Complete! The build context can be found at: /home/ralagarasan/ansible-aap-demo/context

Two options to build and use custom execution environments with Ansible Automation Platform: building and transferring the container image or creating a custom environment.

1. Build and transfer a container image
2. Create a custom execution environment in an unconnected environment

1. Build and transfer a container image
You can create a container image from a connected machine (for example, a developer workstation) with all the dependencies inside and transfer it to the private automation hub (or another supported registry).

Step 1. Create and archive the container image from a connected machine:

## build the container image
$ ansible-builder build --tag my_custom_ee
## Save the container image as archive file
$ podman save --quiet -o my_custom_ee-1.0.tar localhost/my_custom_ee:1.0
Step 2. Copy the archived container image (for example, my_custom_ee-1.0.tar) to the target
Step 3. Load the container image from the TAR file to the system on the unconnected machine, and build the container image: $ podman load -i my_custom_ee-1.0.tar
Step 4. Follow the tag and push process for private automation hub.
$ podman login automationhub22-1.lab.local

Tag the local container image with the private automation hub path:
$ podman tag localhost/network-ee:1.0 automationhub22-1.lab.local/network-ee:1.0

Push the image to the private automation hub (registry):
$ podman push automationhub22-1.lab.local/network-ee:1.0



2. Create a custom execution environment in an unconnected environment
Step 1. Transfer the dependencies to the target unconnected system
Step 2. Prepare the Containerfile with instructions to build the container image for the execution environment:
## Containerfile for custom execution environment
ARG EE_BASE_IMAGE=registry.redhat.io/ansible-automation-platform-22/ee-minimal-rhel8:latest
ARG EE_BUILDER_IMAGE=registry.redhat.io/ansible-automation-platform-22/ansible-builder-rhel8

FROM $EE_BASE_IMAGE

ADD ansible.cfg ansible.cfg
ADD python-packages.tar python
RUN python3 -m pip install -r python/python-packages/requirements.txt --find-links=python/python-packages/ --no-index
Step 3. Build the container image using Podman:
$ podman build -f Containerfile -t localhost/network-ee:1.0
[...]

Looking in links: python/python-packages/
Processing ./python/python-packages/pan_os_python-1.7.3-py2.py3-none-any.whl
Processing ./python/python-packages/pan_python-0.17.0-py2.py3-none-any.whl
Installing collected packages: pan-python, pan-os-python
[...]

Successfully tagged localhost/network-ee:1.0
01e210e05a60dcf49c1b4a2b1bf1e58c49a487823b585233a15d1ecd66910bab
The TAR file is copied, extracted, and the content is installed inside the image.




[Thanks Redhat](https://www.redhat.com/en/blog/ansible-execution-environment-unconnected)

Thursday, April 23, 2026

Ansible_8

Ansible_8

Use Python virtual environments for Ansible


To avoid version conflicts (Ansible, Python libs, collections) and its safe upgrades/testing without breaking system Python.


Intall Required Packages
# dnf install -y python3 python3-pip python3-virtualenv # optional suggestion pkges gcc python3-devel libffi-devel openssl-devel
Create virtual environment
# python3 -m venv ansible-env #This creates a folder ansible-env/ with isolated Python
If venv is missing # virtualenv ansible-env

Activate the environment
# source ansible-env/bin/activate
prompt will change like below
(ansible-env) user@host:~$

Install Ansible inside venv
$ pip install --upgrade pip
$ pip install ansible
$ ansible --version
$ ansible-galaxy collection install community.general
$ ansible-galaxy collection install ansible.posix
$ ansible-galaxy collection install community.vmware
$ ansible-playbook -i inventory.ini playbook.yml

Deactivate
$ ansible-playbook -i inventory.ini playbook.yml

eg
python3 -m venv /home/ralagarasan/uc-01
pip freeze > requirements.txt
pip install -r requirements.txt

Saturday, April 18, 2026

yaml_Ansible_4_map

 Map Structure


Map refers to Dictionary or Key-Value pair structure,
Map Structured-data

A YAML map (mapping) is basically a key → value structure (like a dictionary in Python or JSON object).

name: Alagarasan
role: DevOps Consultant
experience: 8

👉 Here:
name, role, experience → keys
Values → strings / numbers

- name: Create VM
hosts: localhost
vars:
vm_name: test-vm
vm_cpu: 2
👉 Here:
vars is a map
Inside it → vm_name, vm_cpu are keys

Types of Maps
Inline Map
Block Map

Inline Map
person: {name: Alagarasan, role: DevOps Consultant, experience: 8}

Block Map
person:
name: Alagarasan
role: DevOps Consultant
experience: 8

Access full map
- debug:
var: person
Access individual values
- debug:
msg: "{{ person.name }}"

- debug:
msg: "{{ person.role }}"


🔹 Nested Map (Map inside Map)
Inside map we always have key value pairs. We can have multiple key value pairs inside a map. We can also have a map inside a map which is called nested map.

employee:
name: Alagarasan
role: DevOps Consultant
skills:
primary: Ansible
secondary: AWS
Access nested value
- debug:
msg: "{{ person.address.city }}"


👉 Structure:
employee → parent key
Inside it → another map


Map with list
person:
name: Alagarasan
skills:
- Ansible
- Docker
- Kubernetes



Nested Map + List (Real-world 🔥🔥)
servers:
- name: web01
config:
ip: 192.168.1.10
ports:
- 80
- 443

- name: web02
config:
ip: 192.168.1.11
ports:
- 8080
👉 Access:
{{ servers[0].config.ip }}
{{ servers[0].config.ports[1] }}


Yaml_Ansible_3_list

 List (Array) # Lists start with - (dash + space), Indentation matters

A sequence of items, represented as a list (array) in YAML.
Lists can be defined using either block style (with dashes) or inline style (with square brackets).
List Multiple-items

Simple List (Basic)
servers:
- web1
- web2
- db1

Inline List (Flow Style)
servers: [web1, web2, db1]

Nested List
matrix:
- - 1
- 2
- - 3
- 4



List of Maps (Very Important in Ansible 🚀)
users:
- name: John
age: 25
- name: Alice
age: 30

🔥 How to "call" (access) list of maps
Access full list {{ users }}
Access first item {{ users[0] }}
Access specific value {{ users[0].name }} # 👉 Output: John
Loop through list (Most important 🚀)
- name: Print users
debug:
msg: "{{ item.name }} is {{ item.age }} years old"
loop: "{{ users }}"


List inside Map
employee:
name: John
skills:
- Python
- Ansible
- Docker
👉 Here:
employee → map
skills → list inside the map
Access full list {{ employee.skills }}
Access specific item (index) {{ employee.skills[0] }} #👉 Output: Python
Loop through the list
- name: Print skills
debug:
msg: "{{ item }}"
loop: "{{ employee.skills }}"

Use inside message
- name: Print employee info
debug:
msg: "{{ employee.name }} knows {{ employee.skills[1] }}"
👉 Output: John knows Ansible

Structure How to Access
Map → key map.key
List → index list[0]
Map → List map.list_key[0]

Friday, April 17, 2026

YAML_Ansible_2

 


Types of YAML Strings
YAML supports 4 main styles:
🟢 1. Plain Strings (No quotes)
🟡 2. Single-Quoted Strings ' '
🔵 3. Double-Quoted Strings " "
🟣 4. Multi-line Strings (VERY IMPORTANT 🔥)

🟢 1. Plain Strings (No quotes)
name: Alagarasan
role: DevOps Engineer
company: TCS

🟢 2. Double-Quoted Strings
message: "Start\nEnd" # \n is treated as a newline character
👉 Output
Start
End

quote: "He said, \"YAML is easy\"". # \" is treated as a literal double quote or \" lets you escape double quotes
👉 Output
He said, "YAML is easy"

tab: "Hello\tDevOps" # \t is treated as a tab character
quote: "He said \"Hi\"" # \" is treated as a literal double quote


path: "C:\\Program Files\\App"
👉 Output
C:\Program Files\App
💡 Why?
\ is a special character → must escape as \\


Prevent Boolean Conversion
value: "yes"
👉 Output
yes (string)

Tabs / Formatting # \t = tab spacing
text: "Name:\tAlagarasan"
👉 Output
Name: Alagarasan

Multi-line Formatting (Inline)
msg: "Line1\nLine2\nLine3"
👉 Output
Line1
Line2
Line3


🟢 3. Single-Quoted Strings # Everything is treated literally,No special character processing
In YAML, single-quoted strings (' ') are used when you want the content to be taken literally — no escape sequences, no special processing.
name: 'Alagarasan'
city: 'Chennai'
✔ Everything inside ' ' is treated as plain text.

Special Characters (No escaping needed)
path: '/usr/local/bin'
message: 'Hello: World!'
✔ Characters like :, /, ! are safe inside single quotes.

Quotes Inside String
To include a single quote inside, double it ('')
text: 'It''s DevOps'
👉 Output: It's DevOps. # Only one escape:

No Escape Sequences
newline: 'Line1\nLine2'
👉 Output (literal, NOT new line):
Line1\nLine2

❌ \n is NOT interpreted
✔ It stays as plain text

admin: 'true'
🔍 What’s happening here?
In YAML, certain words are reserved keywords (called boolean values):
true, false
yes, no
on, off

If you write:
admin: true
👉 YAML interprets it as a boolean, not a string.

🧠 Why use single quotes?
When you write:
admin: 'true'
👉 Now YAML treats it as a string, not a boolean.

Value written YAML interprets as
true Boolean true
'true' String "true"
"true" String "true"


admin: 'true' # string
enabled: true # boolean


Leading / Trailing Spaces Preserved
value: ' hello '
👉 Output:
" hello "

When to Use Single Quotes
Use ' ' when:

You want literal values
You don’t need escape sequences
String contains special characters like :, #, !
You want safe, predictable parsing




🟣 4. Multi-line Strings (VERY IMPORTANT 🔥)
Literal block (|) → preserves format
message: |
Hello
DevOps
Team

👉 Output:
Hello
DevOps
Team

Folded block (>) → merges lines
message: >
Hello
DevOps
Team

👉 Output:
Hello DevOps Team

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.