DevOps Classroom notes 18/Nov/2026

cat ~/.ssh/id_ed25519.pub | ssh -i ssh_key.pem azureuser@localhost 'mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys'

Ansible facts

  • facts are pieces of information ansible automatically discover

  • host, OS version, Ip address, cpu, memory disk,hostnames and so on …vm level

  • to collection facts by using setup module

# to get all facts info 
ansible all -i hosts  -m ansible.builtin.setup

ansible all -i hosts  -m ansible.builtin.setup -a "filter=ansible_distribution"

Most Common Ansible Facts

A quick reference of frequently used keys inside the ansible_facts dictionary.

Operating System & Distribution

  • ansible_facts['distribution'] — Name of the OS distribution (e.g., Ubuntu, RedHat, AlmaLinux)
  • ansible_facts['distribution_version'] — Full version number of the OS (e.g., 24.04, 9.3)
  • ansible_facts['distribution_major_version'] — Major version number of the OS (e.g., 24, 9)
  • ansible_facts['distribution_release'] — Code name of the OS release (e.g., noble, jammy)
  • ansible_facts['os_family'] — Broad OS family grouping (e.g., Debian, RedHat, Suse)
  • ansible_facts['kernel'] — Active Linux kernel version (e.g., 6.8.0-45-generic)
  • ansible_facts['pkg_mgr'] — Default system package manager (e.g., apt, dnf, yum)
  • ansible_facts['service_mgr'] — Default system init/service manager (e.g., systemd)

System Identity & Environment

  • ansible_facts['hostname'] — Short hostname of the target machine (e.g., web01)
  • ansible_facts['fqdn'] — Fully Qualified Domain Name (e.g., ://example.com)
  • ansible_facts['domain'] — DNS domain name of the host (e.g., example.com)
  • ansible_facts['architecture'] — CPU architecture of the operating system (e.g., x86_64, aarch64)
  • ansible_facts['machine_id'] — Unique systemd machine identifier
  • ansible_facts['virtualization_type'] — Hypervisor or container technology (e.g., kvm, docker, vmware)
  • ansible_facts['virtualization_role'] — Role of the node in virtualization (guest or host)
  • ansible_facts['env'] — Dictionary of remote environment variables (e.g., ansible_facts['env']['PATH'])

Network & IP Addresses

  • ansible_facts['default_ipv4']['address'] — Primary IPv4 address used for default routing
  • ansible_facts['default_ipv4']['interface'] — Network interface name for the default route (e.g., eth0, ens3)
  • ansible_facts['default_ipv4']['gateway'] — Default IPv4 gateway address
  • ansible_facts['default_ipv4']['macaddress'] — MAC address of the primary interface
  • ansible_facts['all_ipv4_addresses'] — List of all active IPv4 addresses on the host
  • ansible_facts['all_ipv6_addresses'] — List of all active IPv6 addresses on the host
  • ansible_facts['interfaces'] — List of all available network interface names (e.g., ['lo', 'eth0'])

Hardware, Memory & Storage

  • ansible_facts['processor_vcpus'] — Total number of logical virtual CPUs
  • ansible_facts['processor_cores'] — Number of physical cores per processor
  • ansible_facts['processor'] — List containing CPU model names and details
  • ansible_facts['memtotal_mb'] — Total physical RAM in megabytes
  • ansible_facts['memfree_mb'] — Currently unused RAM in megabytes
  • ansible_facts['swaptotal_mb'] — Total swap space in megabytes
  • ansible_facts['mounts'] — List of dictionaries describing mounted filesystems
  • ansible_facts['devices'] — Dictionary detailing block storage devices and partitions

Date & Time

  • ansible_facts['date_time']['date'] — Current date in YYYY-MM-DD format
  • ansible_facts['date_time']['time'] — Current time in HH:MM:SS format
  • ansible_facts['date_time']['iso8601'] — UTC timestamp in ISO 8601 format
  • ansible_facts['date_time']['tz'] — System timezone abbreviation (e.g., UTC, IST)

Quick CLI Commands

  • Gather all facts for a host:
    ansible <hostname> -m ansible.builtin.setup
    
  • Filter specific facts:
    ansible <hostname> -m ansible.builtin.setup -a "filter=ansible_distribution*"
    

Task

  1. make tomcat file suppourt both os
  2. create new files under task

Prompt: Create a Custom Ansible Docker Image

Act as a Senior DevOps Engineer and Docker expert.

I want to create a reusable custom Ansible Docker image that works like a command-line tool.

Requirements

  1. Create a Dockerfile to install:

    • Python
    • Ansible
    • OpenSSH client
    • sshpass
    • Git
  2. Create an entrypoint script that accepts and executes any command passed through docker run.

  3. Build the image with the name: custom-ansible:latest

  4. I should be able to pass any Ansible command directly after the Docker image name.

Expected Usage

Check Ansible version:

docker run --rm custom-ansible:latest ansible --version

Run Ansible ping:

docker run --rm \
  -v "$(pwd):/ansible" \
  -v "$HOME/.ssh:/root/.ssh:ro" \
  custom-ansible:latest \
  ansible all -i inventory.ini -m ping

Run Ansible playbook:

docker run --rm \
  -v "$(pwd):/ansible" \
  -v "$HOME/.ssh:/root/.ssh:ro" \
  custom-ansible:latest \
  ansible-playbook -i inventory.ini playbook.yml

Interactive shell:

docker run -it --rm \
  -v "$(pwd):/ansible" \
  --entrypoint /bin/bash \
  custom-ansible:latest

Deliverables

  1. Complete project folder structure.
  2. Dockerfile.
  3. Entrypoint shell script.
  4. Build and run commands.
  5. Support Linux, Ubuntu, and Windows PowerShell usage.
  6. Explain volume mounting and SSH key permissions.
  7. Include troubleshooting steps.
  8. Follow Docker best practices and keep the image lightweight.

Important: Do not hardcode Ansible commands in the Dockerfile. The container must execute whatever command the user passes after the image name using exec "$@".

Provide complete working files with beginner-friendly explanations.

Leave a comment

Turn on JavaScript to leave a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company
Exit mobile version
%%footer%%