ansible学习笔记4-playbooks之setup

ansible 192.168.80.20 -m setup

192.168.80.20 | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "192.168.80.20"
        ], 
        "ansible_all_ipv6_addresses": [
            "fe80::20c:29ff:fec9:1e72"
        ], 
        "ansible_architecture": "x86_64", 
        "ansible_bios_date": "07/31/2013", 
        "ansible_bios_version": "6.00", 
        "ansible_cmdline": {
            "KEYBOARDTYPE": "pc", 
            "KEYTABLE": "us", 
            "LANG": "zh_CN.UTF-8", 
            "quiet": true, 
            "rd_LVM_LV": "VolGroup/lv_root", 
            "rd_NO_DM": true, 
            "rd_NO_LUKS": true, 
            "rd_NO_MD": true, 
            "rhgb": true, 
            "ro": true, 
            "root": "/dev/mapper/VolGroup-lv_root"
        }, 
        "ansible_date_time": {
            "date": "2016-05-12", 
            "day": "12", 
            "epoch": "1463003126", 
            "hour": "05", 
            "iso8601": "2016-05-11T21:45:26Z", 
            "iso8601_basic": "20160512T054526759137", 
            "iso8601_basic_short": "20160512T054526", 
            "iso8601_micro": "2016-05-11T21:45:26.759236Z", 
            "minute": "45", 
            "month": "05", 
            "second": "26", 
            "time": "05:45:26", 
            "tz": "CST", 
            "tz_offset": "+0800", 
            "weekday": "星期四", 
            "weekday_number": "4", 
            "weeknumber": "19", 
            "year": "2016"
        }, 
        "ansible_default_ipv4": {
            "address": "192.168.80.20", 
            "alias": "eth0", 
            "broadcast": "192.168.80.255", 
            "gateway": "192.168.80.2", 
            "interface": "eth0", 
            "macaddress": "00:0c:29:c9:1e:72", 
            "mtu": 1500, 
            "netmask": "255.255.255.0", 
            "network": "192.168.80.0", 
            "type": "ether"
        }, 
        "ansible_default_ipv6": {}, 
        "ansible_devices": {
            "sda": {
                "holders": [], 
                "host": "SCSI storage controller: LSI Logic / Symbios Logic 53c1030 PCI-X Fusion-MPT Dual Ultra320 SCSI (rev 01)", 
                "model": "VMware Virtual S", 
                "partitions": {
                    "sda1": {
                        "sectors": "1024000", 
                        "sectorsize": 512, 
                        "size": "500.00 MB", 
                        "start": "2048"
                    }, 
                    "sda2": {
                        "sectors": "40916992", 
                        "sectorsize": 512, 
                        "size": "19.51 GB", 
                        "start": "1026048"
                    }
                }, 
                "removable": "0", 
                "rotational": "1", 
                "scheduler_mode": "cfq", 
                "sectors": "41943040", 
                "sectorsize": "512", 
                "size": "20.00 GB", 
                "support_discard": "0", 
                "vendor": "VMware,"
            }, 
            "sr0": {
                "holders": [], 
                "host": "IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)", 
                "model": "VMware IDE CDR10", 
                "partitions": {}, 
                "removable": "1", 
                "rotational": "1", 
                "scheduler_mode": "cfq", 
                "sectors": "2097151", 
                "sectorsize": "512", 
                "size": "1024.00 MB", 
                "support_discard": "0", 
                "vendor": "NECVMWar"
            }
        }, 
        "ansible_distribution": "CentOS", 
        "ansible_distribution_major_version": "6", 
        "ansible_distribution_release": "Final", 
        "ansible_distribution_version": "6.5", 
        "ansible_dns": {
            "nameservers": [
                "114.114.114.114"
            ]
        }, 
        "ansible_domain": "localdomain", 
        "ansible_env": {
            "CVS_RSH": "ssh", 
            "G_BROKEN_FILENAMES": "1", 
            "HOME": "/root", 
            "LANG": "zh_CN.UTF-8", 
            "LC_ALL": "zh_CN.UTF-8", 
            "LC_MESSAGES": "zh_CN.UTF-8", 
            "LESSOPEN": "|/usr/bin/lesspipe.sh %s", 
            "LOGNAME": "root", 
            "MAIL": "/var/mail/root", 
            "PATH": "/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin", 
            "PWD": "/root", 
            "QTDIR": "/usr/lib64/qt-3.3", 
            "QTINC": "/usr/lib64/qt-3.3/include", 
            "QTLIB": "/usr/lib64/qt-3.3/lib", 
            "SHELL": "/bin/bash", 
            "SHLVL": "2", 
            "SSH_ASKPASS": "/usr/libexec/openssh/gnome-ssh-askpass", 
            "SSH_CLIENT": "192.168.80.10 54722 22", 
            "SSH_CONNECTION": "192.168.80.10 54722 192.168.80.20 22", 
            "SSH_TTY": "/dev/pts/0", 
            "TERM": "xterm", 
            "USER": "root", 
            "_": "/usr/bin/python"
        }, 
        "ansible_eth0": {
            "active": true, 
            "device": "eth0", 
            "ipv4": {
                "address": "192.168.80.20", 
                "broadcast": "192.168.80.255", 
                "netmask": "255.255.255.0", 
                "network": "192.168.80.0"
            }, 
            "ipv6": [
                {
                    "address": "fe80::20c:29ff:fec9:1e72", 
                    "prefix": "64", 
                    "scope": "link"
                }
            ], 
            "macaddress": "00:0c:29:c9:1e:72", 
            "module": "e1000", 
            "mtu": 1500, 
            "pciid": "0000:02:01.0", 
            "promisc": false, 
            "type": "ether"
        }, 
        "ansible_fips": false, 
        "ansible_form_factor": "Other", 
        "ansible_fqdn": "localhost.localdomain", 
        "ansible_hostname": "localhost", 
        "ansible_interfaces": [
            "lo", 
            "pan0", 
            "eth0"
        ], 
        "ansible_kernel": "2.6.32-431.el6.x86_64", 
        "ansible_lo": {
            "active": true, 
            "device": "lo", 
            "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": 16436, 
            "promisc": false, 
            "type": "loopback"
        }, 
        "ansible_lsb": {
            "codename": "Final", 
            "description": "CentOS release 6.5 (Final)", 
            "id": "CentOS", 
            "major_release": "6", 
            "release": "6.5"
        }, 
        "ansible_lvm": {
            "lvs": {
                "lv_root": {
                    "size_g": "17.57", 
                    "vg": "VolGroup"
                }, 
                "lv_swap": {
                    "size_g": "1.94", 
                    "vg": "VolGroup"
                }
            }, 
            "vgs": {
                "VolGroup": {
                    "free_g": "0", 
                    "num_lvs": "2", 
                    "num_pvs": "1", 
                    "size_g": "19.51"
                }
            }
        }, 
        "ansible_machine": "x86_64", 
        "ansible_machine_id": "20f2093f8670b19b462abf220000000c", 
        "ansible_memfree_mb": 157, 
        "ansible_memory_mb": {
            "nocache": {
                "free": 845, 
                "used": 143
            }, 
            "real": {
                "free": 157, 
                "total": 988, 
                "used": 831
            }, 
            "swap": {
                "cached": 0, 
                "free": 1983, 
                "total": 1983, 
                "used": 0
            }
        }, 
        "ansible_memtotal_mb": 988, 
        "ansible_mounts": [
            {
                "device": "/dev/mapper/VolGroup-lv_root", 
                "fstype": "ext4", 
                "mount": "/", 
                "options": "rw", 
                "size_available": 13993938944, 
                "size_total": 18569568256, 
                "uuid": "f4379dd8-9633-4163-a5ae-10fc3bb438ce"
            }, 
            {
                "device": "/dev/sda1", 
                "fstype": "ext4", 
                "mount": "/boot", 
                "options": "rw", 
                "size_available": 445827072, 
                "size_total": 507744256, 
                "uuid": "38aeb88b-9c2c-4741-b6d8-715ff36526e8"
            }
        ], 
        "ansible_nodename": "localhost.localdomain", 
        "ansible_os_family": "RedHat", 
        "ansible_pan0": {
            "active": false, 
            "device": "pan0", 
            "id": "8000.000000000000", 
            "interfaces": [], 
            "macaddress": "5a:a3:d9:52:2c:97", 
            "mtu": 1500, 
            "promisc": false, 
            "stp": false, 
            "type": "bridge"
        }, 
        "ansible_pkg_mgr": "yum", 
        "ansible_processor": [
            "GenuineIntel", 
            "Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz"
        ], 
        "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 17 d9 0d e6 ad 0e-a6 ec 51 79 00 c9 1e 72", 
        "ansible_product_uuid": "564D17D9-0DE6-AD0E-A6EC-517900C91E72", 
        "ansible_product_version": "None", 
        "ansible_python_version": "2.6.6", 
        "ansible_selinux": {
            "status": "disabled"
        }, 
        "ansible_service_mgr": "upstart", 
        "ansible_ssh_host_key_dsa_public": "AAAAB3NzaC1kc3MAAACBAIYyJsfzRGiNvWTPjeUarXuc3j2ikhtQ8cHRME1ogbiV3Jo3kfUOI1xi2tKWqUvqW65IocpfgHsKl72YOyCnbwM6IagL6QOkHHhV2cjzvcj0NT4EsWhaGEXroIMEkH51w362zYnnuU1IeEuBeLPJikeYqK2tlePMrU4vD8zd3CRdAAAAFQCqI4kOUDeqwpKXU8RkWwNbfCh70QAAAIAV7RiY1Uj3+fPJmBii2F2Y6IOlxBs7vN1fyqlBk0ZlyYwZgJFWVYl+iELTu00ka2fYYcBufz1sZ4JA7EKK1KUiDIaaZnM1QdHl0H4nSb3MJ6sYXhQ4363qSf3ma3ioTlRAI4066GnKfvwRN/jDCWWQ8dRJ0QcX/dVqh5S40h6mFgAAAIBpHoGSBAJMdw67znMLKv89PFbuOnB/cMrb5xD+fGXOnld3B6m8qyaEjXNJVIzZOtLBDHhSf6xvhay6R6C6XM825jTyCLacFFKGdHBqkb0IZzOcrhbcjmc2jBq3sB2n8k7834Jz9bPWSGTWsvo4boIZR+BkBPfQIuDX95JnCzw/1g==", 
        "ansible_ssh_host_key_rsa_public": "AAAAB3NzaC1yc2EAAAABIwAAAQEAoJ8J4kpA2wRFvrKJur9k9bT5vYdgJDKH9gYcTAJu7ZWQyeYqMXFbZ+O4qimN5tP/Rb6KcE5DRaam5L+mhzOXMWLjzsNPNdTD2JTzuylVD1Ki2ayDhZUryaRSTh9O7N+wrH7tEpdJujf5jQTLaF4tBX+5mQwUVPg5A7HqXulvcuJK9AJO02tIDWarfyDyZBz5gYIpd4/HcuWXL1z/cmAH7bXoxAxGTZ+XgezjE+G5sUnK812EOeuUzfRjupUJGyAtS6mIZMTjnuDgNRi7a8lVpgfsG7E6ksZxJdlzgIjYpOLO2PAUBhlW0kqhVoXMcj4i7AfNahC7IPQdeNeC10qVOQ==", 
        "ansible_swapfree_mb": 1983, 
        "ansible_swaptotal_mb": 1983, 
        "ansible_system": "Linux", 
        "ansible_system_vendor": "VMware, Inc.", 
        "ansible_uptime_seconds": 71942, 
        "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", 
        "module_setup": true
    }, 
    "changed": false
}

使用setup中的值

{{ansible_eth0.ipv4.address}}

字典用"."连接

列表用"_"连接

时间: 2024-10-10 17:06:36

ansible学习笔记4-playbooks之setup的相关文章

运维自动化工具ansible学习笔记

利用五一假期的时间学习了下ansible,看了一天的官方文档,对其中需要注意的地方,做下笔记整理下思绪. 一.简介 Ansible是与puppet.saltstack类似的集群管理工具,其优点是仅需要ssh和Python即可使用,而不像puppet.saltstack那样都需要客户端.puppet与saltstack这2个软件都需要安装客户端,而saltstack与ansible很相似,都是属于python流的,但saltstack不是很稳定:puppet虽然稳定,但命令执行的时候,需要配置模块

Ansible 学习笔记

最近因为需要管理很多台机器,而这些机器又需要频繁重新安装,实在受不了Puppet需要在每个客户机上都安装一遍,于是转头开始学些Ansible.根据这段时间的使用,这个确实是神器,唯一的感觉就是相见恨晚. 下面纪录一下最近的学习心得. Ansible是基于单客户端,多服务器端的模式.这可能是和Puppet等基于单服务器端,多客户端的最大不同. Ansible是用Python编写的,易于扩展,便于调试 下面以最常见的需要客户端和所有服务器建立ssh信任关系为例,看看ansible多么简单.首先建立h

ansible学习笔记(二):ansible for CentOS6安装

### 最近有点儿时间了,再继续学习Asible,本节尝试使用pip安装ansible for CentOS6.5,其中OS是最小化安装. 2.2 Installing ansible on CentOS 6.5 2.2.1 pip安装Ansible ###(1) 准备环境: # python -V       # 版本:Python 2.6.6 # yum install gcc gcc-c++ # yum install git -y # yum install python-devel p

ansible 学习笔记(上)

运维工具 当前常见的运维工具(Configuration)有以下一种puppret(ruby)saltstack(python)chefcfengine.... Command and Control; fabricfunc 程序发布: 手动发布 脚本发布 发布程序(运维程序) 程序发布要求:1.不能影响用户体验:2.系统不能停机:3.不能导致系统故障或造成系统完全不可用: 灰度发布模型(考虑以下两种维度):1.主机:2.用户: 发布思路: /webapps/tuangou /webapps/t

ansible学习笔记9-playbooks之include

task include files 在不同tasks之间plays和playbooks可以重复调用.include files可以达成目的 系统通过使用include task来完美实现role定义,记住,playbook中的play最终 目的是映射系统群到多个roles中 cat tasks/foo.yml --- # possibly saved as tasks/foo.yml - name: placeholder foo command: /bin/foo - name: place

ansible学习笔记

一.ansible的基本简介: ansible式什么? Ansible 是一个适用于成百上千规模的受控节点的配置管理.应用程序部署.内部服务编排等诸多功能于一身的极为简单的IT运维自动化工具引擎,基于Python开 发.她无需代理,很容易部署,除SSH外没有其他安全基础设施/配置要求.她使用了一个非常简单的语言(YAML),让你可以编写自己的自动化作业脚本. ansible式怎样工作的? Ansible连接到受控机,并推送一个称为"Modules"的应用程序到受控机上,Ansible然

ansible学习笔记(一)

最近在学习使用ansible,为了未来的大规模部署应用做准备,这东西比我之前用过的puppet,saltstack都简便一点,没有client端,也不需要额外配置,基本上手技能用,据说在国外的热门程度目前也超过saltstack了. 下面就开始零星的记录吧. 确保服务在running状态 tasks:   - name: make sure apache is running     service: name=httpd state=running 写web server的vhost配置文件可

ansible学习笔记1-Inventory文件

Inventory文件 Ansible可同时操作属于一个组的多台主机.组合主机之间的关系通过inventory文件配置,默认的文件路径为/etc/ansible/hosts 除了默认文件外,你还可以同时使用多个inventory文件,也可以从动态源或云上拉取inventory配置信息 ------------------------------------------------------------------------ 主机与组 /etc/ansible/hosts文件的格式与windo

[ansible学习笔记]Error: ansible requires the stdlib json or simplejson module, neither was found!

1.执行ansible命令的时候客户端rhel56-192.168.209.133 出现以下错误: [[email protected] ansible]# ansible all -m command -a "python -V" -u reed SSH password: rhel56-192.168.209.133 | FAILED | rc=0 >> Error: ansible requires the stdlib json or simplejson modu