Ansible setup module


  • از این ماژول برای دریافت اطلاعاتی جامع از خادم‌های تحت مدیریت استفاده می‌شود.

  • به عنوان مثال کد زیر باعث می‌شود تا :
    • اطلاعاتی جامع از خادم‌های تحت مدیریت جمع آوری شود.
# ansible -i hosts.list debian-servers -m setup
  • در صورتی که دستور بالا به صورت موفقیت آمیز اجرا شده باشد، خروجی‌ای مشابه زیر دریافت خواهید کرد :
172.16.0.247 | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "172.16.0.247"
        ],
        "ansible_all_ipv6_addresses": [
            "fe80::20c:29ff:feb6:5ab0"
        ],
        "ansible_apparmor": {
            "status": "enabled"
        },
        "ansible_architecture": "x86_64",
        "ansible_bios_date": "09/19/2018",
        "ansible_bios_version": "6.00",
        "ansible_cmdline": {
            "BOOT_IMAGE": "/boot/vmlinuz-4.19.0-8-amd64",
            "quiet": true,
            "ro": true,
            "root": "UUID=a478c48f-295f-4ffb-b6b0-38ec64cd306c"
        },
        "ansible_date_time": {
            "date": "2020-03-13",
            "day": "13",
            "epoch": "1584111401",
            "hour": "10",
            "iso8601": "2020-03-13T14:56:41Z",
            "iso8601_basic": "20200313T105641786929",
            "iso8601_basic_short": "20200313T105641",
            "iso8601_micro": "2020-03-13T14:56:41.786979Z",
            "minute": "56",
            "month": "03",
            "second": "41",
            "time": "10:56:41",
            "tz": "EDT",
            "tz_offset": "-0400",
            "weekday": "Friday",
            "weekday_number": "5",
            "weeknumber": "10",
            "year": "2020"
        },
        "ansible_default_ipv4": {
            "address": "172.16.0.247",
            "alias": "ens192",
            "broadcast": "172.16.255.255",
            "gateway": "172.16.0.251",
            "interface": "ens192",
            "macaddress": "00:0c:29:b6:5a:b0",
            "mtu": 1500,
            "netmask": "255.255.0.0",
            "network": "172.16.0.0",
            "type": "ether"
        },
        "ansible_default_ipv6": {},
        "ansible_device_links": {
            "ids": {},
            "labels": {},
            "masters": {},
            "uuids": {
                "sda1": [
                    "a478c48f-295f-4ffb-b6b0-38ec64cd306c"
                ],
                "sda5": [
                    "f5f6151c-59ae-4d06-ba2f-bf6a51f706a6"
                ]
            }
        },
        "ansible_devices": {
            "sda": {
                "holders": [],
                "host": "Serial Attached SCSI controller: VMware PVSCSI SCSI Controller (rev 02)",
                "links": {
                    "ids": [],
                    "labels": [],
                    "masters": [],
                    "uuids": []
                },
                "model": "Virtual disk",
                "partitions": {
                    "sda1": {
                        "holders": [],
                        "links": {
                            "ids": [],
                            "labels": [],
                            "masters": [],
                            "uuids": [
                                "a478c48f-295f-4ffb-b6b0-38ec64cd306c"
                            ]
                        },
                        "sectors": "205518848",
                        "sectorsize": 512,
                        "size": "98.00 GB",
                        "start": "2048",
                        "uuid": "a478c48f-295f-4ffb-b6b0-38ec64cd306c"
                    },
                    "sda2": {
                        "holders": [],
                        "links": {
                            "ids": [],
                            "labels": [],
                            "masters": [],
                            "uuids": []
                        },
                        "sectors": "2",
                        "sectorsize": 512,
                        "size": "1.00 KB",
                        "start": "205522942",
                        "uuid": null
                    },
                    "sda5": {
                        "holders": [],
                        "links": {
                            "ids": [],
                            "labels": [],
                            "masters": [],
                            "uuids": [
                                "f5f6151c-59ae-4d06-ba2f-bf6a51f706a6"
                            ]
                        },
                        "sectors": "4190208",
                        "sectorsize": 512,
                        "size": "2.00 GB",
                        "start": "205522944",
                        "uuid": "f5f6151c-59ae-4d06-ba2f-bf6a51f706a6"
                    }
                },
                "removable": "0",
                "rotational": "0",
                "sas_address": null,
                "sas_device_handle": null,
                "scheduler_mode": "mq-deadline",
                "sectors": "209715200",
                "sectorsize": "512",
                "size": "100.00 GB",
                "support_discard": "1048576",
                "vendor": "VMware",
                "virtual": 1
            }
        },
        "ansible_distribution": "Debian",
        "ansible_distribution_file_parsed": true,
        "ansible_distribution_file_path": "/etc/os-release",
        "ansible_distribution_file_variety": "Debian",
        "ansible_distribution_major_version": "10",
        "ansible_distribution_release": "buster",
        "ansible_distribution_version": "10.3",
        "ansible_dns": {
            "nameservers": [
                "8.8.8.8"
            ]
        },
        "ansible_domain": "",
        "ansible_effective_group_id": 0,
        "ansible_effective_user_id": 0,
        "ansible_ens192": {
            "active": true,
            "device": "ens192",
            "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",
                "hw_tc_offload": "off [fixed]",
                "l2_fwd_offload": "off [fixed]",
                "large_receive_offload": "on",
                "loopback": "off [fixed]",
                "netns_local": "off [fixed]",
                "ntuple_filters": "off [fixed]",
                "receive_hashing": "off [fixed]",
                "rx_all": "off [fixed]",
                "rx_checksumming": "on",
                "rx_fcs": "off [fixed]",
                "rx_gro_hw": "off [fixed]",
                "rx_udp_tunnel_port_offload": "off [fixed]",
                "rx_vlan_filter": "on [fixed]",
                "rx_vlan_offload": "on",
                "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",
                "tx_checksum_ipv4": "off [fixed]",
                "tx_checksum_ipv6": "off [fixed]",
                "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_partial": "off [fixed]",
                "tx_gso_robust": "off [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_udp_segmentation": "off [fixed]",
                "tx_udp_tnl_csum_segmentation": "off [fixed]",
                "tx_udp_tnl_segmentation": "off [fixed]",
                "tx_vlan_offload": "on",
                "tx_vlan_stag_hw_insert": "off [fixed]",
                "udp_fragmentation_offload": "off",
                "vlan_challenged": "off [fixed]"
            },
            "hw_timestamp_filters": [],
            "ipv4": {
                "address": "172.16.0.247",
                "broadcast": "172.16.255.255",
                "netmask": "255.255.0.0",
                "network": "172.16.0.0"
            },
            "ipv6": [
                {
                    "address": "fe80::20c:29ff:feb6:5ab0",
                    "prefix": "64",
                    "scope": "link"
                }
            ],
            "macaddress": "00:0c:29:b6:5a:b0",
            "module": "vmxnet3",
            "mtu": 1500,
            "pciid": "0000:0b:00.0",
            "promisc": false,
            "speed": 10000,
            "timestamping": [
                "rx_software",
                "software"
            ],
            "type": "ether"
        },
        "ansible_env": {
            "HOME": "/root",
            "LANG": "en_US.UTF-8",
            "LOGNAME": "root",
            "MAIL": "/var/mail/root",
            "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            "PWD": "/root",
            "SHELL": "/bin/bash",
            "SHLVL": "0",
            "SSH_CLIENT": "172.16.0.250 56670 22",
            "SSH_CONNECTION": "172.16.0.250 56670 172.16.0.247 22",
            "SSH_TTY": "/dev/pts/1",
            "TERM": "xterm",
            "USER": "root",
            "XDG_RUNTIME_DIR": "/run/user/0",
            "XDG_SESSION_CLASS": "user",
            "XDG_SESSION_ID": "50",
            "XDG_SESSION_TYPE": "tty",
            "_": "/bin/sh"
        },
        "ansible_fips": false,
        "ansible_form_factor": "Other",
        "ansible_fqdn": "debian10",
        "ansible_hostname": "debian10",
        "ansible_interfaces": [
            "lo",
            "ens192"
        ],
        "ansible_is_chroot": false,
        "ansible_kernel": "4.19.0-8-amd64",
        "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]",
                "hw_tc_offload": "off [fixed]",
                "l2_fwd_offload": "off [fixed]",
                "large_receive_offload": "off [fixed]",
                "loopback": "on [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_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_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_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]",
                "udp_fragmentation_offload": "off",
                "vlan_challenged": "on [fixed]"
            },
            "hw_timestamp_filters": [],
            "ipv4": {
                "address": "127.0.0.1",
                "broadcast": "host",
                "netmask": "255.0.0.0",
                "network": "127.0.0.0"
            },
            "ipv6": [
                {
                    "address": "::1",
                    "prefix": "128",
                    "scope": "host"
                }
            ],
            "mtu": 65536,
            "promisc": false,
            "timestamping": [
                "tx_software",
                "rx_software",
                "software"
            ],
            "type": "loopback"
        },
        "ansible_local": {},
        "ansible_lsb": {
            "codename": "buster",
            "description": "Debian GNU/Linux 10 (buster)",
            "id": "Debian",
            "major_release": "10",
            "release": "10"
        },
        "ansible_machine": "x86_64",
        "ansible_machine_id": "35f1cc4d1d354fbaa6459c53ee8b623c",
        "ansible_memfree_mb": 520,
        "ansible_memory_mb": {
            "nocache": {
                "free": 839,
                "used": 147
            },
            "real": {
                "free": 520,
                "total": 986,
                "used": 466
            },
            "swap": {
                "cached": 0,
                "free": 2045,
                "total": 2045,
                "used": 0
            }
        },
        "ansible_memtotal_mb": 986,
        "ansible_mounts": [
            {
                "block_available": 23496043,
                "block_size": 4096,
                "block_total": 25155598,
                "block_used": 1659555,
                "device": "/dev/sda1",
                "fstype": "ext4",
                "inode_available": 6376166,
                "inode_total": 6422528,
                "inode_used": 46362,
                "mount": "/",
                "options": "rw,relatime,errors=remount-ro",
                "size_available": 96239792128,
                "size_total": 103037329408,
                "uuid": "a478c48f-295f-4ffb-b6b0-38ec64cd306c"
            }
        ],
        "ansible_nodename": "debian10",
        "ansible_os_family": "Debian",
        "ansible_pkg_mgr": "apt",
        "ansible_processor": [
            "0",
            "GenuineIntel",
            "Intel(R) Core(TM) i3-8100 CPU @ 3.60GHz"
        ],
        "ansible_processor_cores": 1,
        "ansible_processor_count": 1,
        "ansible_processor_threads_per_core": 1,
        "ansible_processor_vcpus": 1,
        "ansible_product_name": "VMware Virtual Platform",
        "ansible_product_serial": "VMware-56 4d 0f b0 0e 8c c5 b3-7d 80 15 9d b1 b6 5a b0",
        "ansible_product_uuid": "b00f4d56-8c0e-b3c5-7d80-159db1b65ab0",
        "ansible_product_version": "None",
        "ansible_python": {
            "executable": "/usr/bin/python",
            "has_sslcontext": true,
            "type": "cpython",
            "version": {
                "major": 3,
                "micro": 3,
                "minor": 7,
                "releaselevel": "final",
                "serial": 0
            },
            "version_info": [
                3,
                7,
                3,
                "final",
                0
            ]
        },
        "ansible_python_version": "3.7.3",
        "ansible_real_group_id": 0,
        "ansible_real_user_id": 0,
        "ansible_selinux": {
            "status": "disabled"
        },
        "ansible_selinux_python_present": true,
        "ansible_service_mgr": "systemd",
        "ansible_ssh_host_key_ecdsa_public": "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBHGcS1++AA8X5hIWu6ZPaKYjyBNCvxbp9QqtwNgQbzoJkDgKZV1I9aouE3gTuigYABXJ7muh4yArSRp6DYcKMNs=",
        "ansible_ssh_host_key_ed25519_public": "AAAAC3NzaC1lZDI1NTE5AAAAILQIlhZwUkWgqj3Te5T4EtI1nUER/ZOepJHkkEkvVMcX",
        "ansible_ssh_host_key_rsa_public": "AAAAB3NzaC1yc2EAAAADAQABAAABAQCqnfwTJ32MP7k/mxakIEW9MwiL5o55WCY9VG8Q7cMsMak+kKiB+QC+Mw04AUlzkv0F4q3KoPi+3EELIFm0mdinClkZLQgyuOKy3bt7sLFd3z9DpR1NsEfzCqTFxAXc2M2YoMxMHVZQqmyDmvpDLGEHHJaIZ+T1KqWpumbYCI8cMOFq6iUsEslWckIyk4xMvGpiP8GbX+VykBlDUZ77zZrD0rWmrSguD2cUP4+hvjqeYFgGdQjBj+nrH5x/TqE/TvBOZzz6eK4TFgaaKgYTAoYvvzTFtS2S2Suvq05UqIwvtkS6bDqX5WM7jZUZvIcSeIt3Wk27kBodzP1mhziMhHS1",
        "ansible_swapfree_mb": 2045,
        "ansible_swaptotal_mb": 2045,
        "ansible_system": "Linux",
        "ansible_system_capabilities": [
            "cap_chown",
            "cap_dac_override",
            "cap_dac_read_search",
            "cap_fowner",
            "cap_fsetid",
            "cap_kill",
            "cap_setgid",
            "cap_setuid",
            "cap_setpcap",
            "cap_linux_immutable",
            "cap_net_bind_service",
            "cap_net_broadcast",
            "cap_net_admin",
            "cap_net_raw",
            "cap_ipc_lock",
            "cap_ipc_owner",
            "cap_sys_module",
            "cap_sys_rawio",
            "cap_sys_chroot",
            "cap_sys_ptrace",
            "cap_sys_pacct",
            "cap_sys_admin",
            "cap_sys_boot",
            "cap_sys_nice",
            "cap_sys_resource",
            "cap_sys_time",
            "cap_sys_tty_config",
            "cap_mknod",
            "cap_lease",
            "cap_audit_write",
            "cap_audit_control",
            "cap_setfcap",
            "cap_mac_override",
            "cap_mac_admin",
            "cap_syslog",
            "cap_wake_alarm",
            "cap_block_suspend",
            "cap_audit_read+ep"
        ],
        "ansible_system_capabilities_enforced": "True",
        "ansible_system_vendor": "VMware, Inc.",
        "ansible_uptime_seconds": 12608,
        "ansible_user_dir": "/root",
        "ansible_user_gecos": "root",
        "ansible_user_gid": 0,
        "ansible_user_id": "root",
        "ansible_user_shell": "/bin/bash",
        "ansible_user_uid": 0,
        "ansible_userspace_architecture": "x86_64",
        "ansible_userspace_bits": "64",
        "ansible_virtualization_role": "guest",
        "ansible_virtualization_type": "VMware",
        "gather_subset": [
            "all"
        ],
        "module_setup": true
    },
    "changed": false
}

  • نکته: با استفاده از پارامتر gather_subset می‌توان تعیین نمود که تنها اطلاعاتی خاص جمع آوری شود.
  • به عنوان مثال دستور زیر باعث می‌شود تا :
    • اطلاعات مربوط به سخت افزار گروهی از خادم‌های تحت مدیریت، جمع آوری نشود :
# ansible -i hosts.list debian-servers -m setup -a 'gather_subset="!hardware"'

  • به عنوان مثال دستور زیر باعث می‌شود تا :
    • فقط اطلاعات مربوط به شبکه‌ی خادم‌های تحت مدیریت، جمع آوری شود.
# ansible -i hosts.list debian-servers -m setup -a 'gather_subset=network'

  • به منظور مطالعه‌ی بیشتر لینک‌های زیر پیشنهاد می‌شود :
https://docs.ansible.com/ansible/latest/modules/setup_module.html
  • همچنین برای مطالعه بییشتر در خصوص این ماژول، می‌توان از دستور ansible-doc استفاده نمود.

  • آزمایش شده بر روی Ansible نسخه‌ی 2.5.1
  • آزمایش شده بر روی سیستم عامل Ubuntu 18.04

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *