DevOps Classroom notes 09/Mar/2025

Ansible

Facts

  • Facts are information about the node which ansible collects
  • Ansible has a module setup which can collect facts
172.31.4.82 | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "172.31.4.82"
        ],
        "ansible_all_ipv6_addresses": [
            "fe80::80e:10ff:fed7:6479"
        ],
        "ansible_apparmor": {
            "status": "enabled"
        },
        "ansible_architecture": "x86_64",
        "ansible_bios_date": "08/24/2006",
        "ansible_bios_vendor": "Xen",
        "ansible_bios_version": "4.11.amazon",
        "ansible_board_asset_tag": "NA",
        "ansible_board_name": "NA",
        "ansible_board_serial": "NA",
        "ansible_board_vendor": "NA",
        "ansible_board_version": "NA",
        "ansible_chassis_asset_tag": "NA",
        "ansible_chassis_serial": "NA",
        "ansible_chassis_vendor": "Xen",
        "ansible_chassis_version": "NA",
        "ansible_cmdline": {
            "BOOT_IMAGE": "/vmlinuz-6.8.0-1024-aws",
            "console": "ttyS0",
            "nvme_core.io_timeout": "4294967295",
            "panic": "-1",
            "ro": true,
            "root": "PARTUUID=2bb9818b-3393-4017-8da7-c739e7b96eac"
        },
        "ansible_date_time": {
            "date": "2025-03-09",
            "day": "09",
            "epoch": "1741487831",
            "epoch_int": "1741487831",
            "hour": "02",
            "iso8601": "2025-03-09T02:37:11Z",
            "iso8601_basic": "20250309T023711440704",
            "iso8601_basic_short": "20250309T023711",
            "iso8601_micro": "2025-03-09T02:37:11.440704Z",
            "minute": "37",
            "month": "03",
            "second": "11",
            "time": "02:37:11",
            "tz": "UTC",
            "tz_dst": "UTC",
            "tz_offset": "+0000",
            "weekday": "Sunday",
            "weekday_number": "0",
            "weeknumber": "09",
            "year": "2025"
        },
        "ansible_default_ipv4": {
            "address": "172.31.4.82",
            "alias": "enX0",
            "broadcast": "",
            "gateway": "172.31.0.1",
            "interface": "enX0",
            "macaddress": "0a:0e:10:d7:64:79",
            "mtu": 9001,
            "netmask": "255.255.240.0",
            "network": "172.31.0.0",
            "prefix": "20",
            "type": "ether"
        },
        "ansible_default_ipv6": {},
        "ansible_device_links": {
            "ids": {},
            "labels": {
                "xvda1": [
                    "cloudimg-rootfs"
                ],
                "xvda15": [
                    "UEFI"
                ],
                "xvda16": [
                    "BOOT"
                ]
            },
            "masters": {},
            "uuids": {
                "xvda1": [
                    "104656f3-cbcd-4c1a-bbe2-5bb510be86c0"
                ],
                "xvda15": [
                    "534B-8AD0"
                ],
                "xvda16": [
                    "91942573-b0ea-4e42-8692-2a195de77cba"
                ]
            }
        },
        "ansible_devices": {
            "loop0": {
                "holders": [],
                "host": "",
                "links": {
                    "ids": [],
                    "labels": [],
                    "masters": [],
                    "uuids": []
                },
                "model": null,
                "partitions": {},
                "removable": "0",
                "rotational": "0",
                "sas_address": null,
                "sas_device_handle": null,
                "scheduler_mode": "none",
                "sectors": "53912",
                "sectorsize": "512",
                "size": "26.32 MB",
                "support_discard": "4096",
                "vendor": null,
                "virtual": 1
            },
            "loop1": {
                "holders": [],
                "host": "",
                "links": {
                    "ids": [],
                    "labels": [],
                    "masters": [],
                    "uuids": []
                },
                "model": null,
                "partitions": {},
                "removable": "0",
                "rotational": "0",
                "sas_address": null,
                "sas_device_handle": null,
                "scheduler_mode": "none",
                "sectors": "151288",
                "sectorsize": "512",
                "size": "73.87 MB",
                "support_discard": "4096",
                "vendor": null,
                "virtual": 1
            },
            "loop2": {
                "holders": [],
                "host": "",
                "links": {
                    "ids": [],
                    "labels": [],
                    "masters": [],
                    "uuids": []
                },
                "model": null,
                "partitions": {},
                "removable": "0",
                "rotational": "0",
                "sas_address": null,
                "sas_device_handle": null,
                "scheduler_mode": "none",
                "sectors": "151328",
                "sectorsize": "512",
                "size": "73.89 MB",
                "support_discard": "4096",
                "vendor": null,
                "virtual": 1
            },
            "loop3": {
                "holders": [],
                "host": "",
                "links": {
                    "ids": [],
                    "labels": [],
                    "masters": [],
                    "uuids": []
                },
                "model": null,
                "partitions": {},
                "removable": "0",
                "rotational": "0",
                "sas_address": null,
                "sas_device_handle": null,
                "scheduler_mode": "none",
                "sectors": "91008",
                "sectorsize": "512",
                "size": "44.44 MB",
                "support_discard": "4096",
                "vendor": null,
                "virtual": 1
            },
            "loop4": {
                "holders": [],
                "host": "",
                "links": {
                    "ids": [],
                    "labels": [],
                    "masters": [],
                    "uuids": []
                },
                "model": null,
                "partitions": {},
                "removable": "0",
                "rotational": "0",
                "sas_address": null,
                "sas_device_handle": null,
                "scheduler_mode": "none",
                "sectors": "0",
                "sectorsize": "512",
                "size": "0.00 Bytes",
                "support_discard": "4096",
                "vendor": null,
                "virtual": 1
            },
            "loop5": {
                "holders": [],
                "host": "",
                "links": {
                    "ids": [],
                    "labels": [],
                    "masters": [],
                    "uuids": []
                },
                "model": null,
                "partitions": {},
                "removable": "0",
                "rotational": "1",
                "sas_address": null,
                "sas_device_handle": null,
                "scheduler_mode": "none",
                "sectors": "0",
                "sectorsize": "512",
                "size": "0.00 Bytes",
                "support_discard": "512",
                "vendor": null,
                "virtual": 1
            },
            "loop6": {
                "holders": [],
                "host": "",
                "links": {
                    "ids": [],
                    "labels": [],
                    "masters": [],
                    "uuids": []
                },
                "model": null,
                "partitions": {},
                "removable": "0",
                "rotational": "1",
                "sas_address": null,
                "sas_device_handle": null,
                "scheduler_mode": "none",
                "sectors": "0",
                "sectorsize": "512",
                "size": "0.00 Bytes",
                "support_discard": "512",
                "vendor": null,
                "virtual": 1
            },
            "loop7": {
                "holders": [],
                "host": "",
                "links": {
                    "ids": [],
                    "labels": [],
                    "masters": [],
                    "uuids": []
                },
                "model": null,
                "partitions": {},
                "removable": "0",
                "rotational": "1",
                "sas_address": null,
                "sas_device_handle": null,
                "scheduler_mode": "none",
                "sectors": "0",
                "sectorsize": "512",
                "size": "0.00 Bytes",
                "support_discard": "512",
                "vendor": null,
                "virtual": 1
            },
            "xvda": {
                "holders": [],
                "host": "",
                "links": {
                    "ids": [],
                    "labels": [],
                    "masters": [],
                    "uuids": []
                },
                "model": null,
                "partitions": {
                    "xvda1": {
                        "holders": [],
                        "links": {
                            "ids": [],
                            "labels": [
                                "cloudimg-rootfs"
                            ],
                            "masters": [],
                            "uuids": [
                                "104656f3-cbcd-4c1a-bbe2-5bb510be86c0"
                            ]
                        },
                        "sectors": "14677983",
                        "sectorsize": 512,
                        "size": "7.00 GB",
                        "start": "2099200",
                        "uuid": "104656f3-cbcd-4c1a-bbe2-5bb510be86c0"
                    },
                    "xvda14": {
                        "holders": [],
                        "links": {
                            "ids": [],
                            "labels": [],
                            "masters": [],
                            "uuids": []
                        },
                        "sectors": "8192",
                        "sectorsize": 512,
                        "size": "4.00 MB",
                        "start": "2048",
                        "uuid": null
                    },
                    "xvda15": {
                        "holders": [],
                        "links": {
                            "ids": [],
                            "labels": [
                                "UEFI"
                            ],
                            "masters": [],
                            "uuids": [
                                "534B-8AD0"
                            ]
                        },
                        "sectors": "217088",
                        "sectorsize": 512,
                        "size": "106.00 MB",
                        "start": "10240",
                        "uuid": "534B-8AD0"
                    },
                    "xvda16": {
                        "holders": [],
                        "links": {
                            "ids": [],
                            "labels": [
                                "BOOT"
                            ],
                            "masters": [],
                            "uuids": [
                                "91942573-b0ea-4e42-8692-2a195de77cba"
                            ]
                        },
                        "sectors": "1869825",
                        "sectorsize": 512,
                        "size": "913.00 MB",
                        "start": "227328",
                        "uuid": "91942573-b0ea-4e42-8692-2a195de77cba"
                    }
                },
                "removable": "0",
                "rotational": "0",
                "sas_address": null,
                "sas_device_handle": null,
                "scheduler_mode": "mq-deadline",
                "sectors": "16777216",
                "sectorsize": "512",
                "size": "8.00 GB",
                "support_discard": "512",
                "vendor": null,
                "virtual": 1
            }
        },
        "ansible_distribution": "Ubuntu",
        "ansible_distribution_file_parsed": true,
        "ansible_distribution_file_path": "/etc/os-release",
        "ansible_distribution_file_variety": "Debian",
        "ansible_distribution_major_version": "24",
        "ansible_distribution_release": "noble",
        "ansible_distribution_version": "24.04",
        "ansible_dns": {
            "nameservers": [
                "127.0.0.53"
            ],
            "options": {
                "edns0": true,
                "trust-ad": true
            },
            "search": [
                "ap-south-1.compute.internal"
            ]
        },
        "ansible_domain": "ap-south-1.compute.internal",
        "ansible_effective_group_id": 1001,
        "ansible_effective_user_id": 1001,
        "ansible_enX0": {
            "active": true,
            "device": "enX0",
            "features": {
                "esp_hw_offload": "off [fixed]",
                "esp_tx_csum_hw_offload": "off [fixed]",
                "fcoe_mtu": "off [fixed]",
                "generic_receive_offload": "on",
                "generic_segmentation_offload": "on",
                "highdma": "off [fixed]",
                "hsr_dup_offload": "off [fixed]",
                "hsr_fwd_offload": "off [fixed]",
                "hsr_tag_ins_offload": "off [fixed]",
                "hsr_tag_rm_offload": "off [fixed]",
                "hw_tc_offload": "off [fixed]",
                "l2_fwd_offload": "off [fixed]",
                "large_receive_offload": "off [fixed]",
                "loopback": "off [fixed]",
                "macsec_hw_offload": "off [fixed]",
                "netns_local": "off [fixed]",
                "ntuple_filters": "off [fixed]",
                "receive_hashing": "off [fixed]",
                "rx_all": "off [fixed]",
                "rx_checksumming": "on [fixed]",
                "rx_fcs": "off [fixed]",
                "rx_gro_hw": "off [fixed]",
                "rx_gro_list": "off",
                "rx_udp_gro_forwarding": "off",
                "rx_udp_tunnel_port_offload": "off [fixed]",
                "rx_vlan_filter": "off [fixed]",
                "rx_vlan_offload": "off [fixed]",
                "rx_vlan_stag_filter": "off [fixed]",
                "rx_vlan_stag_hw_parse": "off [fixed]",
                "scatter_gather": "on",
                "tcp_segmentation_offload": "on",
                "tls_hw_record": "off [fixed]",
                "tls_hw_rx_offload": "off [fixed]",
                "tls_hw_tx_offload": "off [fixed]",
                "tx_checksum_fcoe_crc": "off [fixed]",
                "tx_checksum_ip_generic": "off [fixed]",
                "tx_checksum_ipv4": "on [fixed]",
                "tx_checksum_ipv6": "on",
                "tx_checksum_sctp": "off [fixed]",
                "tx_checksumming": "on",
                "tx_esp_segmentation": "off [fixed]",
                "tx_fcoe_segmentation": "off [fixed]",
                "tx_gre_csum_segmentation": "off [fixed]",
                "tx_gre_segmentation": "off [fixed]",
                "tx_gso_list": "off [fixed]",
                "tx_gso_partial": "off [fixed]",
                "tx_gso_robust": "on [fixed]",
                "tx_ipxip4_segmentation": "off [fixed]",
                "tx_ipxip6_segmentation": "off [fixed]",
                "tx_lockless": "off [fixed]",
                "tx_nocache_copy": "off",
                "tx_scatter_gather": "on",
                "tx_scatter_gather_fraglist": "off [fixed]",
                "tx_sctp_segmentation": "off [fixed]",
                "tx_tcp6_segmentation": "on",
                "tx_tcp_ecn_segmentation": "off [fixed]",
                "tx_tcp_mangleid_segmentation": "off",
                "tx_tcp_segmentation": "on",
                "tx_tunnel_remcsum_segmentation": "off [fixed]",
                "tx_udp_segmentation": "off [fixed]",
                "tx_udp_tnl_csum_segmentation": "off [fixed]",
                "tx_udp_tnl_segmentation": "off [fixed]",
                "tx_vlan_offload": "off [fixed]",
                "tx_vlan_stag_hw_insert": "off [fixed]",
                "vlan_challenged": "off [fixed]"
            },
            "hw_timestamp_filters": [],
            "ipv4": {
                "address": "172.31.4.82",
                "broadcast": "",
                "netmask": "255.255.240.0",
                "network": "172.31.0.0",
                "prefix": "20"
            },
            "ipv6": [
                {
                    "address": "fe80::80e:10ff:fed7:6479",
                    "prefix": "64",
                    "scope": "link"
                }
            ],
            "macaddress": "0a:0e:10:d7:64:79",
            "mtu": 9001,
            "pciid": "vif-0",
            "promisc": false,
            "timestamping": [],
            "type": "ether"
        },
        "ansible_env": {
            "DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/user/1001/bus",
            "HOME": "/home/devops",
            "LANG": "C.UTF-8",
            "LOGNAME": "devops",
            "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin",
            "PWD": "/home/devops",
            "SHELL": "/bin/bash",
            "SHLVL": "0",
            "SSH_CLIENT": "172.31.10.176 51528 22",
            "SSH_CONNECTION": "172.31.10.176 51528 172.31.4.82 22",
            "SSH_TTY": "/dev/pts/0",
            "TERM": "xterm-256color",
            "USER": "devops",
            "XDG_RUNTIME_DIR": "/run/user/1001",
            "XDG_SESSION_CLASS": "user",
            "XDG_SESSION_ID": "2",
            "XDG_SESSION_TYPE": "tty",
            "_": "/bin/sh"
        },
        "ansible_fibre_channel_wwn": [],
        "ansible_fips": false,
        "ansible_form_factor": "Other",
        "ansible_fqdn": "ip-172-31-4-82.ap-south-1.compute.internal",
        "ansible_hostname": "ip-172-31-4-82",
        "ansible_hostnqn": "",
        "ansible_interfaces": [
            "enX0",
            "lo"
        ],
        "ansible_is_chroot": false,
        "ansible_iscsi_iqn": "",
        "ansible_kernel": "6.8.0-1024-aws",
        "ansible_kernel_version": "#26-Ubuntu SMP Tue Feb 18 17:22:37 UTC 2025",
        "ansible_lo": {
            "active": true,
            "device": "lo",
            "features": {
                "esp_hw_offload": "off [fixed]",
                "esp_tx_csum_hw_offload": "off [fixed]",
                "fcoe_mtu": "off [fixed]",
                "generic_receive_offload": "on",
                "generic_segmentation_offload": "on",
                "highdma": "on [fixed]",
                "hsr_dup_offload": "off [fixed]",
                "hsr_fwd_offload": "off [fixed]",
                "hsr_tag_ins_offload": "off [fixed]",
                "hsr_tag_rm_offload": "off [fixed]",
                "hw_tc_offload": "off [fixed]",
                "l2_fwd_offload": "off [fixed]",
                "large_receive_offload": "off [fixed]",
                "loopback": "on [fixed]",
                "macsec_hw_offload": "off [fixed]",
                "netns_local": "on [fixed]",
                "ntuple_filters": "off [fixed]",
                "receive_hashing": "off [fixed]",
                "rx_all": "off [fixed]",
                "rx_checksumming": "on [fixed]",
                "rx_fcs": "off [fixed]",
                "rx_gro_hw": "off [fixed]",
                "rx_gro_list": "off",
                "rx_udp_gro_forwarding": "off",
                "rx_udp_tunnel_port_offload": "off [fixed]",
                "rx_vlan_filter": "off [fixed]",
                "rx_vlan_offload": "off [fixed]",
                "rx_vlan_stag_filter": "off [fixed]",
                "rx_vlan_stag_hw_parse": "off [fixed]",
                "scatter_gather": "on",
                "tcp_segmentation_offload": "on",
                "tls_hw_record": "off [fixed]",
                "tls_hw_rx_offload": "off [fixed]",
                "tls_hw_tx_offload": "off [fixed]",
                "tx_checksum_fcoe_crc": "off [fixed]",
                "tx_checksum_ip_generic": "on [fixed]",
                "tx_checksum_ipv4": "off [fixed]",
                "tx_checksum_ipv6": "off [fixed]",
                "tx_checksum_sctp": "on [fixed]",
                "tx_checksumming": "on",
                "tx_esp_segmentation": "off [fixed]",
                "tx_fcoe_segmentation": "off [fixed]",
                "tx_gre_csum_segmentation": "off [fixed]",
                "tx_gre_segmentation": "off [fixed]",
                "tx_gso_list": "on",
                "tx_gso_partial": "off [fixed]",
                "tx_gso_robust": "off [fixed]",
                "tx_ipxip4_segmentation": "off [fixed]",
                "tx_ipxip6_segmentation": "off [fixed]",
                "tx_lockless": "on [fixed]",
                "tx_nocache_copy": "off [fixed]",
                "tx_scatter_gather": "on [fixed]",
                "tx_scatter_gather_fraglist": "on [fixed]",
                "tx_sctp_segmentation": "on",
                "tx_tcp6_segmentation": "on",
                "tx_tcp_ecn_segmentation": "on",
                "tx_tcp_mangleid_segmentation": "on",
                "tx_tcp_segmentation": "on",
                "tx_tunnel_remcsum_segmentation": "off [fixed]",
                "tx_udp_segmentation": "on",
                "tx_udp_tnl_csum_segmentation": "off [fixed]",
                "tx_udp_tnl_segmentation": "off [fixed]",
                "tx_vlan_offload": "off [fixed]",
                "tx_vlan_stag_hw_insert": "off [fixed]",
                "vlan_challenged": "on [fixed]"
            },
            "hw_timestamp_filters": [],
            "ipv4": {
                "address": "127.0.0.1",
                "broadcast": "",
                "netmask": "255.0.0.0",
                "network": "127.0.0.0",
                "prefix": "8"
            },
            "ipv6": [
                {
                    "address": "::1",
                    "prefix": "128",
                    "scope": "host"
                }
            ],
            "mtu": 65536,
            "promisc": false,
            "timestamping": [],
            "type": "loopback"
        },
        "ansible_loadavg": {
            "15m": 0.14599609375,
            "1m": 0.2734375,
            "5m": 0.3291015625
        },
        "ansible_local": {},
        "ansible_locally_reachable_ips": {
            "ipv4": [
                "127.0.0.0/8",
                "127.0.0.1",
                "172.31.4.82"
            ],
            "ipv6": [
                "::1",
                "fe80::80e:10ff:fed7:6479"
            ]
        },
        "ansible_lsb": {
            "codename": "noble",
            "description": "Ubuntu 24.04.1 LTS",
            "id": "Ubuntu",
            "major_release": "24",
            "release": "24.04"
        },
        "ansible_lvm": "N/A",
        "ansible_machine": "x86_64",
        "ansible_machine_id": "ec2ca1e4e6a3d40ae1e617357a7ee4ff",
        "ansible_memfree_mb": 256,
        "ansible_memory_mb": {
            "nocache": {
                "free": 723,
                "used": 234
            },
            "real": {
                "free": 256,
                "total": 957,
                "used": 701
            },
            "swap": {
                "cached": 0,
                "free": 0,
                "total": 0,
                "used": 0
            }
        },
        "ansible_memtotal_mb": 957,
        "ansible_mounts": [
            {
                "block_available": 1163346,
                "block_size": 4096,
                "block_total": 1758594,
                "block_used": 595248,
                "device": "/dev/root",
                "dump": 0,
                "fstype": "ext4",
                "inode_available": 804479,
                "inode_total": 917504,
                "inode_used": 113025,
                "mount": "/",
                "options": "rw,relatime,discard,errors=remount-ro,commit=30",
                "passno": 0,
                "size_available": 4765065216,
                "size_total": 7203201024,
                "uuid": "104656f3-cbcd-4c1a-bbe2-5bb510be86c0"
            },
            {
                "block_available": 0,
                "block_size": 131072,
                "block_total": 211,
                "block_used": 211,
                "device": "/dev/loop0",
                "dump": 0,
                "fstype": "squashfs",
                "inode_available": 0,
                "inode_total": 14,
                "inode_used": 14,
                "mount": "/snap/amazon-ssm-agent/9881",
                "options": "ro,nodev,relatime,errors=continue,threads=single",
                "passno": 0,
                "size_available": 0,
                "size_total": 27656192,
                "uuid": "N/A"
            },
            {
                "block_available": 0,
                "block_size": 131072,
                "block_total": 591,
                "block_used": 591,
                "device": "/dev/loop1",
                "dump": 0,
                "fstype": "squashfs",
                "inode_available": 0,
                "inode_total": 14248,
                "inode_used": 14248,
                "mount": "/snap/core22/1722",
                "options": "ro,nodev,relatime,errors=continue,threads=single",
                "passno": 0,
                "size_available": 0,
                "size_total": 77463552,
                "uuid": "N/A"
            },
            {
                "block_available": 0,
                "block_size": 131072,
                "block_total": 592,
                "block_used": 592,
                "device": "/dev/loop2",
                "dump": 0,
                "fstype": "squashfs",
                "inode_available": 0,
                "inode_total": 14262,
                "inode_used": 14262,
                "mount": "/snap/core22/1748",
                "options": "ro,nodev,relatime,errors=continue,threads=single",
                "passno": 0,
                "size_available": 0,
                "size_total": 77594624,
                "uuid": "N/A"
            },
            {
                "block_available": 0,
                "block_size": 131072,
                "block_total": 356,
                "block_used": 356,
                "device": "/dev/loop3",
                "dump": 0,
                "fstype": "squashfs",
                "inode_available": 0,
                "inode_total": 608,
                "inode_used": 608,
                "mount": "/snap/snapd/23545",
                "options": "ro,nodev,relatime,errors=continue,threads=single",
                "passno": 0,
                "size_available": 0,
                "size_total": 46661632,
                "uuid": "N/A"
            },
            {
                "block_available": 175000,
                "block_size": 4096,
                "block_total": 225380,
                "block_used": 50380,
                "device": "/dev/xvda16",
                "dump": 0,
                "fstype": "ext4",
                "inode_available": 57891,
                "inode_total": 58496,
                "inode_used": 605,
                "mount": "/boot",
                "options": "rw,relatime",
                "passno": 0,
                "size_available": 716800000,
                "size_total": 923156480,
                "uuid": "91942573-b0ea-4e42-8692-2a195de77cba"
            },
            {
                "block_available": 201172,
                "block_size": 512,
                "block_total": 213663,
                "block_used": 12491,
                "device": "/dev/xvda15",
                "dump": 0,
                "fstype": "vfat",
                "inode_available": 0,
                "inode_total": 0,
                "inode_used": 0,
                "mount": "/boot/efi",
                "options": "rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro",
                "passno": 0,
                "size_available": 103000064,
                "size_total": 109395456,
                "uuid": "534B-8AD0"
            }
        ],
        "ansible_nodename": "ip-172-31-4-82",
        "ansible_os_family": "Debian",
        "ansible_pkg_mgr": "apt",
        "ansible_proc_cmdline": {
            "BOOT_IMAGE": "/vmlinuz-6.8.0-1024-aws",
            "console": [
                "tty1",
                "ttyS0"
            ],
            "nvme_core.io_timeout": "4294967295",
            "panic": "-1",
            "ro": true,
            "root": "PARTUUID=2bb9818b-3393-4017-8da7-c739e7b96eac"
        },
        "ansible_processor": [
            "0",
            "GenuineIntel",
            "Intel(R) Xeon(R) CPU E5-2686 v4 @ 2.30GHz"
        ],
        "ansible_processor_cores": 1,
        "ansible_processor_count": 1,
        "ansible_processor_nproc": 1,
        "ansible_processor_threads_per_core": 1,
        "ansible_processor_vcpus": 1,
        "ansible_product_name": "HVM domU",
        "ansible_product_serial": "NA",
        "ansible_product_uuid": "NA",
        "ansible_product_version": "4.11.amazon",
        "ansible_python": {
            "executable": "/usr/bin/python3.12",
            "has_sslcontext": true,
            "type": "cpython",
            "version": {
                "major": 3,
                "micro": 3,
                "minor": 12,
                "releaselevel": "final",
                "serial": 0
            },
            "version_info": [
                3,
                12,
                3,
                "final",
                0
            ]
        },
        "ansible_python_version": "3.12.3",
        "ansible_real_group_id": 1001,
        "ansible_real_user_id": 1001,
        "ansible_selinux": {
            "status": "disabled"
        },
        "ansible_selinux_python_present": true,
        "ansible_service_mgr": "systemd",
        "ansible_ssh_host_key_ecdsa_public": "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBGNFYE8sIjJJEiz7xyyUsO2Ro9J4WMdPMGgNetThYt2J0jfehCQj6RZwWXiUw67KG2X8BgR8PcRAPJghOp52ars=",
        "ansible_ssh_host_key_ecdsa_public_keytype": "ecdsa-sha2-nistp256",
        "ansible_ssh_host_key_ed25519_public": "AAAAC3NzaC1lZDI1NTE5AAAAIDSOzQT90/G8pugrFZEwTVROn17OoQN0ARbuw97rETEB",
        "ansible_ssh_host_key_ed25519_public_keytype": "ssh-ed25519",
        "ansible_ssh_host_key_rsa_public": "AAAAB3NzaC1yc2EAAAADAQABAAABgQDHLzJ5w0jkSZmRGYqWEoened8Jc22H2lniB3OW/vot6pLUqD8LvncrBmiPPSLTNNaoyrBn5M1mNrMJreOht7yX6uA8mpt6J9V8+whlnNHE/uwdZ43TJF0g2+xyS2SlW1YDM1RrbZmo0XESu6B9eZ5N/p6HlffHLKhkSmbVX63r8COX70Vn0RKAsBovfjWLuClJUMXC6YDToN27wQLFvTKFsb5xxBkWnZ8/oLcPTtcLmvMNJakpGTiW1QHT+6R/vPEO40XFrDh2X0g7d/Sp9b1nlinbqK9qIiD0gl9htrTWwhUvbdWA/eV67LWz78gC1RepEsio5B7TZr5OSO1XyDZoh3yVTv2GejfudcOP3hm0DKyc2unXNylPkZsF/iBO6465FEI7OPv31MGn6hSw5EOLYjChSEiO3z7eXQCJW5YnLpgWxn1qVsQkiEwOPWQ5VmMs3GvVlaHl4KVhEDmnn1nXDI+UDZ4JtKZLh/b6nD8fC1lBIAKgcW/TgI+hxZ5PH1U=",
        "ansible_ssh_host_key_rsa_public_keytype": "ssh-rsa",
        "ansible_swapfree_mb": 0,
        "ansible_swaptotal_mb": 0,
        "ansible_system": "Linux",
        "ansible_system_capabilities": [
            ""
        ],
        "ansible_system_capabilities_enforced": "True",
        "ansible_system_vendor": "Xen",
        "ansible_uptime_seconds": 167,
        "ansible_user_dir": "/home/devops",
        "ansible_user_gecos": ",,,",
        "ansible_user_gid": 1001,
        "ansible_user_id": "devops",
        "ansible_user_shell": "/bin/bash",
        "ansible_user_uid": 1001,
        "ansible_userspace_architecture": "x86_64",
        "ansible_userspace_bits": "64",
        "ansible_virtualization_role": "guest",
        "ansible_virtualization_tech_guest": [
            "xen"
        ],
        "ansible_virtualization_tech_host": [],
        "ansible_virtualization_type": "xen",
        "discovered_interpreter_python": "/usr/bin/python3.12",
        "gather_subset": [
            "all"
        ],
        "module_setup": true
    },
    "changed": false
}

Conditional execution

  • Our playbook works only for ubuntu, try failing the playbook if it run on different distribution
  • conditionals
  • Sample
tasks:
    - name: fail if distribution is not supported
      ansible.builtin.fail:
        msg: "This playbook works only on ubuntu distribution"
      when: ansible_facts['distribution'] != "Ubuntu"
  • when: ansible_facts['distribution'] != "Ubuntu" will excute the above task only when distribution is ubuntu and in other cases it will fail.

Exercise

  • Create a ansible setup with two nodes one ubuntu and one redhat
    Preview
  • I Want you to write a playbook which installs apache on both redhat and ubuntu
  • Manual steps:
    • ubuntu:
      bash
      sudo apt update
      sudo apt install apache2 -y
    • redhat
      sudo dnf install httpd -y
      sudo systemctl enable httpd
      sudo systemctl start httpd
  • Playbook
---
- name: installing apache
  hosts: all
  become: yes
  tasks:
    - name: install apache
      ansible.builtin.apt:
        name: apache2
        update_cache: yes
        state: present
      when: ansible_facts['distribution'] == "Ubuntu"
    - name: install httpd
      ansible.builtin.dnf:
        name: httpd
        state: present
      when: ansible_facts['distribution'] == "RedHat"
    - name: enable and start httpd
      ansible.builtin.systemd_service:
        name: httpd
        enabled: yes
        state: started
      when: ansible_facts['distribution'] == "RedHat"

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

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

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube