YAML & Ansible


  • YAML = data structure
  • Ansible = loops + conditions + variables
  •  

    Ansible Playbook YAML keywords

    1.Most Important Keywords
    name
    hosts
    tasks
    vars
    roles

    2.Modules (Core Workhorses)
    shell 
    command
    debug
    copy - local to remote (only)
    fetch - remote to local
    template

    3.Conditions & Control
    when
    loop
    loop_control
    register

    4.Task Behavior Control
    changed_when
    failed_when
    ignore_errors
    become

    5.tags

    6.Facts & Host Info
    inventory_hostname
    hostvars

    7.blocks


    ##ansible basics
    Ansible automates tasks on remote machines using SSH + YAML playbooks
    Role = reusable bundle of tasks, templates, variables, and handlers for a specific function

    ## frequently used ansible modules 
    - template: generate config
    - command: apply config
    - command: save config
    - debug: verify


    root@digi-oss:/home/labadmin# cat inventory.ini
    [bb]
    server1 ansible_host=172.27.64.115 ansible_user=labadmin
    server2 ansible_host=172.27.64.116 ansible_user=labadmin
    server3 ansible_host=172.27.64.117 ansible_user=labadmin

    [fo]
    fanout1 ansible_host=172.27.71.240 ansible_user=admin
    fanout2 ansible_host=172.27.71.243 ansible_user=admin

    root@digi-oss:/home/labadmin# ansible -i inventory.ini bb -a "date"
    server1 | CHANGED | rc=0 >>
    Tue 31 Mar 2026 03:34:25 PM UTC
    server2 | CHANGED | rc=0 >>
    Tue Mar 31 03:35:16 PM UTC 2026
    server3 | CHANGED | rc=0 >>
    Tue Mar 31 03:30:57 PM UTC 2026

    Comments

    Popular posts from this blog

    eBGP sonic lab + Ansible config & validation

    SONiC-2

    RDMA RoCE