Posts

Showing posts from April, 2026

Ansible_Facts

  Facts Ansible implements fact collecting through the a module called the setup module. It collects detailed information (called facts) from managed nodes. It collects detailed information (called facts) from managed nodes. By default, Ansible automatically runs setup at the start of every play. $ ansible ubuntu -m setup - name : Gather facts manually hosts : all tasks : - name : Run setup module ansible.builtin.setup : - debug : msg : "Host {{ ansible_hostname }} has {{ ansible_memtotal_mb }} MB RAM" Filtering Facts Collect only specific facts - name : Get only network-related facts ansible.builtin.setup : filter : ansible_default_ipv4 - name : Get only facts that start with 'ansible_processor' ansible.builtin.setup : filter : 'ansible_processor*' - name : Get only facts that start with 'ansible_processor' and 'ansible_mem' ansible.builtin.setup : filter : 'ansible_processor*' , ...

Ansible Variables

  Variables Variables can be used in tasks, as well as in template files. You reference variables by using {{ variable }}. Ansible replaces this {{ variable }} with the value of the variable value eg vars : conf_file : /etc/nginx/sites/default Ansible will substitute "{{ conf_file }}" with /etc/nginx/sites/default when it executes this task. Ansible uses the Jinja2 template engine to implement templating We use the .j2 extension to indicate that the file is a Jinja2 template. However, we can use a any extension if you like. Ansible also uses the Jinja2 template engine to evaluate variables in playbooks. Loop When you want to run a task with each item from a list, you can use loop. A loop executes the task multiple times, each time replacing item with different values from the specified list. Handlers Handlers are one of the conditional forms, A handler is similar to a task, but it runs only if it has been notified by a task. A task will run the notification if Ansible reco...

Ansible_inventory Parameters

  Inventory Parameters inventory is called as collection of hosts inventory parameters are variables or settings you define in your inventory file to control how hosts and groups behave during playbook execution. ansible_host # Hostname or IP address to SSH to ansible_port # Port to SSH to ansible_user # User to SSH as ansible_password # Password to use for SSH authentication ansible_ssh_private_key_file # SSH private key to use for SSH authentication ansible_become=true ansible_become_user=root ansible_become_method=sudo(or)su localhost ansible_connection=local Custom variable web1 app_port=8080 env=prod ansible_connection Ansible supports multiple transports to connect hosts The default transport, smart Ansible will check whether the locally installed SSH client supports a feature called ControlPersist. If the SSH client supports ControlPersist, Ansible will use the local SSH client. If not, the smart tran...

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 w...

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/ra...

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 ...

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 - ...

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 \n End" # \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 \t DevOps" # \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 / For...

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 ...