ansible 文档

xueyufeihu 贡献于2015-12-29

作者 IBM_USER  创建于2007-10-18 01:23:00   修改者sunkewei  修改于2015-07-27 02:00:00字数9900

文档摘要: ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。ansible是基于模块工作的,本身没有批量部署的能力。真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架。主要包括: (1)、 连接插件connection plugins:负责和被监控端实现通信; (2)、host inventory:指定操作的主机,是一个配置文件里面定义监控的主机; (3)、各种模块核心模块、command模块、自定义模块; (4)、借助于插件完成记录日志邮件等功能; (5)、playbook:剧本执行多个任务时,非必需可以让节点一次性运行多个任务。
关键词:

 ansible文档 上海姚记彩票科技有限公司 2015年7月 IBM专有信息声明 本方案建议书属商业机密文件,书中的所有信息均为IBM机密信息,仅供国家电网“SG186”工程综合网管系统试点单位建设项目组使用。务请妥善保管并且仅在与项目有关人员范围内使用,未经IBM公司明确作出的书面许可,不得为任何目的、以任何形式或手段(包括电子、机械、复印、录音或其他形式)对本文档的任何部分进行复制、存储、引入检索系统或者传播。 尽管IBM已经尽力使本文档内容的完整性和有效性,但仍可能有技术方面不够准确的地方或印刷错误。若需求有所变化,IBM将对有关内容进行相对应的调整,并在本建议书未来版本中体现。 IBM是国际商业机器公司的注册商标。本文档提及的其他公司、产品和服务的名称,可能是其他公司的商标或服务的标志。 Copyright©2018IBM China Company Limited All rights reserved 关于本文档 文档信息 文档名称 国家电网“SG186”工程综合网管系统试点单位建设项目详细设计报告 作者 IBM 全球服务中国有限公司 说明 文件名称 国家电网“SG186”工程综合网管系统试点单位建设项目详细设计报告.doc 修订历史 Rev Section Type Date Author Remarks 1.0 2007/08/14 IBM 文档创建 内容范围 本文档是国家电网“SG186”工程试点单位的综合网管系统详细设计结果的说明。 适用的对象 本文档仅适用于国家电网“SG186”工程综合网管系统试点单位建设项目的决策者、评估者。 目 录 1 引言 6 1.1 ansible的安装(centos 6下) 6 1.2 ansible相关目录 6 1.3 简单例子。 7 2 创建kvm客户机 7 2.1 创建客户机 7 2.2 通过virtsh console命令连接客户机。 12 3 Virt-manager图形管理工具。 14 3.1 虚拟机的启动,暂停和关闭。 14 3.2 查看虚拟机详细信息。 16 3.3 查看虚拟机的监控信息 20 4 Virt-view管理工具 22 5 Kvm存储池管理 22 5.1 基于目录结构的存储池 22 5.2 使用virtsh创建基于目录的存储池 26 5.3 使用virtsh命令删除存储池。 28 6 Virsh命令 28 6.1 Virsh常用命令 28 6.2 域管理命令。 29 6.3 宿主机管理命令 30 6.4 网络管理命令 30 6.5 存储池和存储卷的管理命令 31 6.6 其他命令 32 7 libguestfs-tools 32 7.1 libguestfs-tools的安装 32 7.2 相关命令 32 7.3 使用guestfish查看虚拟机信息 33 7.4 用guestfish操作虚拟机内部文件 34 8 存储卷的管理 34 1 概述 1.1 简介 ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。ansible是基于模块工作的,本身没有批量部署的能力。真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架。主要包括: (1)、 连接插件connection plugins:负责和被监控端实现通信; (2)、host inventory:指定操作的主机,是一个配置文件里面定义监控的主机; (3)、各种模块核心模块、command模块、自定义模块; (4)、借助于插件完成记录日志邮件等功能; (5)、playbook:剧本执行多个任务时,非必需可以让节点一次性运行多个任务。 1.2 总体架构. 1.3 特性 (1)、no agents:不需要在被管控主机上安装任何客户端; (2)、no server:无服务器端,使用时直接运行命令即可; (3)、modules in any languages:基于模块工作,可使用任意语言开发模块; (4)、yaml,not code:使用yaml语言定制剧本playbook; (5)、ssh by default:基于SSH工作; (6)、strong multi-tier solution:可实现多级指挥。 1.4 优点 1)、轻量级,无需在客户端安装agent,更新时,只需在操作机上进行一次更新即可; (2)、批量任务执行可以写成脚本,而且不用分发到远程就可以执行; (3)、使用python编写,维护更简单,ruby语法过于复杂; (4)、支持sudo。 1.5 任务执行流程 2 引言 2.1 ansible的安装(centos 6下) ntos6.3默认是没有ansible的yum源的,所以我们需要下载相关的yum源,然后使用yum命令安装即可。 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo yum -y install ansiblelibvirt-client-0.10.2-46.el6_6.6.x86_64 2.2 ansible相关目录 /etc/ansible目录是ansible的配置文件目录,主要用对ansible进行配置相关的文件。里面目前有ansible.cfg, hosts和roles目录3个文件组成。 [root@localhost ansible]# ls ansible.cfg hosts roles /usr/bin/目录里与ansible相关的命令有: [root@localhost bin]# ls /usr/bin/ | grep -i ansible ansible ansible-doc ansible-galaxy ansible-playbook ansible-pull ansible-vault /usr/lib/python2.6/site-packages/ansible/modules/目录包含于ansible相关的模块文件。目前里面有Core,extras2个目录。 2.3 简单例子。 首先我们定义几个被监控主机,编辑/etc /ansible/hosts文件如下: [root@ansible-server ansible]# cat hosts [client] 192.168.200.189 ansible_ssh_user=root ansible_ssh_pass=111111 192.168.200.105 ansible_ssh_user=root ansible_ssh_pass=123com 192.168.200.107 ansible_ssh_user=root ansible_ssh_pass=123com 这里我们定义了一个client组,下面包含3个主机,以及通过关键字ansible_ssh_user和ansible_ssh_pass定义登录主机的用户名和密码(真实环境不建议这么做,推荐使用ssh key的方式操作)。因为ansible默认的方式就是通过ssh key的方式进行对远程主机的操作的,因此还需要我们修改下默认配置文件。Vi /etc/ansible/ansible.cfg 把host_key_checking = False前边的注释#给去掉。 例1:主机存活率ping检测。 [root@ansible-server ansible]# ansible client -m ping 192.168.200.189 | success >> { "changed": false, "ping": "pong" } 192.168.200.105 | success >> { "changed": false, "ping": "pong" } 192.168.200.107 | success >> { "changed": false, "ping": "pong" } 例2:主机负载检测。 [root@ansible-server ansible]# ansible client -a uptime 192.168.200.189 | success | rc=0 >> 18:52:13 up 2 days, 2:00, 3 users, load average: 3.06, 2.73, 2.44 192.168.200.105 | success | rc=0 >> 06:52:34 up 1 day, 20:50, 3 users, load average: 2.24, 2.12, 2.02 192.168.200.107 | success | rc=0 >> 06:52:34 up 1 day, 23:50, 2 users, load average: 2.34, 2.14, 2.04 3 Ansible常用模块 3.1 Setup模块:看主机相关信息。 [root@ansible-server ansible]# ansible client -m setup 192.168.200.107 | success >> { "ansible_facts": { "ansible_all_ipv4_addresses": [ "192.168.200.107" ], "ansible_all_ipv6_addresses": [ "fe80::5054:ff:feaf:f15" ], "ansible_architecture": "x86_64", "ansible_bios_date": "01/01/2007", "ansible_bios_version": "0.5.1", "ansible_cmdline": { "KEYBOARDTYPE": "pc", "KEYTABLE": "us", "LANG": "en_US.UTF-8", "SYSFONT": "latarcyrheb-sun16", "nomodeset": true, "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": "2015-07-23", "day": "23", "epoch": "1437649104", "hour": "06", "iso8601": "2015-07-23T10:58:24Z", "iso8601_micro": "2015-07-23T10:58:24.819212Z", "minute": "58", "month": "07", "second": "24", "time": "06:58:24", "tz": "EDT", "tz_offset": "-0400", "weekday": "Thursday", "year": "2015" }, "ansible_default_ipv4": { "address": "192.168.200.107", "alias": "eth1", "gateway": "192.168.200.254", "interface": "eth1", "macaddress": "52:54:00:af:0f:15", "mtu": 1500, "netmask": "255.255.255.0", "network": "192.168.200.0", "type": "ether" }, "ansible_default_ipv6": {}, "ansible_devices": { "sda": { "holders": [], "host": "IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]", "model": "QEMU HARDDISK", "partitions": { "sda1": { "sectors": "1024000", "sectorsize": 512, "size": "500.00 MB", "start": "2048" }, "sda2": { "sectors": "15751168", "sectorsize": 512, "size": "7.51 GB", "start": "1026048" } }, "removable": "0", "rotational": "1", "scheduler_mode": "cfq", "sectors": "16777216", "sectorsize": "512", "size": "8.00 GB", "support_discard": "0", "vendor": "ATA" }, "sr0": { "holders": [], "host": "IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]", "model": "QEMU DVD-ROM", "partitions": {}, "removable": "1", "rotational": "1", "scheduler_mode": "cfq", "sectors": "2097151", "sectorsize": "512", "size": "1024.00 MB", "support_discard": "0", "vendor": "QEMU" } }, "ansible_distribution": "CentOS", "ansible_distribution_major_version": "6", "ansible_distribution_release": "Final", "ansible_distribution_version": "6.3", "ansible_domain": "localdomain", "ansible_env": { "CVS_RSH": "ssh", "G_BROKEN_FILENAMES": "1", "HOME": "/root", "LANG": "C", "LC_CTYPE": "C", "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", "SELINUX_LEVEL_REQUESTED": "", "SELINUX_ROLE_REQUESTED": "", "SELINUX_USE_CURRENT_RANGE": "", "SHELL": "/bin/bash", "SHLVL": "2", "SSH_CLIENT": "192.168.200.117 60286 22", "SSH_CONNECTION": "192.168.200.117 60286 192.168.200.107 22", "SSH_TTY": "/dev/pts/1", "TERM": "xterm", "USER": "root", "_": "/usr/bin/python" }, "ansible_eth1": { "active": true, "device": "eth1", "ipv4": { "address": "192.168.200.107", "netmask": "255.255.255.0", "network": "192.168.200.0" }, "ipv6": [ { "address": "fe80::5054:ff:feaf:f15", "prefix": "64", "scope": "link" } ], "macaddress": "52:54:00:af:0f:15", "module": "8139cp", "mtu": 1500, "promisc": false, "type": "ether" }, "ansible_fips": false, "ansible_form_factor": "Other", "ansible_fqdn": "localhost.localdomain", "ansible_hostname": "localhost", "ansible_interfaces": [ "lo", "eth1" ], "ansible_kernel": "2.6.32-279.el6.x86_64", "ansible_lo": { "active": true, "device": "lo", "ipv4": { "address": "127.0.0.1", "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.3 (Final)", "id": "CentOS", "major_release": "6", "release": "6.3" }, "ansible_machine": "x86_64", "ansible_machine_id": "fd408e32dcc3e14128d91d15000000c7", "ansible_memfree_mb": 142, "ansible_memory_mb": { "nocache": { "free": 325, "used": 165 }, "real": { "free": 142, "total": 490, "used": 348 }, "swap": { "cached": 0, "free": 2004, "total": 2015, "used": 11 } }, "ansible_memtotal_mb": 490, "ansible_mounts": [ { "device": "/dev/mapper/VolGroup-lv_root", "fstype": "ext4", "mount": "/", "options": "rw", "size_available": 2184896512, "size_total": 5854007296, "uuid": "3a00dbea-b473-4cb7-9531-38e3ec3a2799" }, { "device": "/dev/sda1", "fstype": "ext4", "mount": "/boot", "options": "rw", "size_available": 447758336, "size_total": 507744256, "uuid": "e78e36bd-9470-4439-9758-3b7e62b81144" } ], "ansible_nodename": "localhost.localdomain", "ansible_os_family": "RedHat", "ansible_pkg_mgr": "yum", "ansible_processor": [ "AuthenticAMD", "QEMU Virtual CPU version (cpu64-rhel6)" ], "ansible_processor_cores": 1, "ansible_processor_count": 1, "ansible_processor_threads_per_core": 1, "ansible_processor_vcpus": 1, "ansible_product_name": "KVM", "ansible_product_serial": "NA", "ansible_product_uuid": "35114233-9028-346C-C448-C4A6BFE014E7", "ansible_product_version": "RHEL 6.6.0 PC", "ansible_python_version": "2.6.6", "ansible_selinux": false, "ansible_ssh_host_key_dsa_public": "AAAAB3NzaC1kc3MAAACBALuL/FKsnc0d4DBcbJaiZ+10QqmnobcKnQKRmh6g/ARPR8eC6ZmhnBLHJsYrejYaVXHgZb7hjPhmfmv+Cb7wH/TV04PA+XnrTS2yAaPoQpxiP36HhWbj2k2xQLKfocv8u6QELIfZtrR4+Cn/lN8DFenzfnFIa3Ixr2O6xRUbId39AAAAFQCl1GTHe1rx6UN8SdqsFxEIE1gd+wAAAIEAtkU1VRYDFhcIYuN1ZqgPqRFz9zEcsLEIlypMvtD4H2O2QSJ7YHqKUHiiws1pdl/Gl638+SNUb6V/m/99RbRpCaQBca85AHyTjpH6hKzIQAgsq12B5X9a+cT3bQO3hDYc3skVylj7hD5vv2dj4O0b3q/JDzSUbli17rm447+Icg4AAACAAsz7eh2M04V4AeX9+mq6eyPRsRRhks4L4PgF8mLru+UDXz5PqYCYBze25Pluw4oiImJcGCyi5Iyok7cDR8G3D3cSszo6zIDgLqYJOg2QZgxKTCGnhMaUqTdgSMVFnNrfvTGfJdrCvcNTKkZvDhiI9r3GFc5Wh1IH5C7LhqEzR/0=", "ansible_ssh_host_key_rsa_public": "AAAAB3NzaC1yc2EAAAABIwAAAQEA8AYb8nehYMVPgRN4kiXcyJYvIX4clWSNahBt/0gJOXTqIFHLMamu3C4swnbl6LHnONpazN9X/tFdSs8xH0KvGaCTU7sJtjw0eHZ/KxaQ9kVy9WJljQpAwk1hmc/M8hmwt2GCd0u9EPtnLvGac9+eAZ441V3q1Xwm0zvOVo6WLZ9D1eAbJkmDeFdbzIrVnLm2BmOezlYRDQnFyHKSQ7Epfw16SFPNW6VonmmR8nijm93zYK57V3/QNgQMqigxOqXq6Tgoa7dek3BV7cBnq5tpQ/kPjMB595GA9aN3YekyQqG/pM0yx4m67bKOrULxF7Wqt4CNwLGtfaCifW/7FjaivQ==", "ansible_swapfree_mb": 2004, "ansible_swaptotal_mb": 2015, "ansible_system": "Linux", "ansible_system_vendor": "Red Hat", "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": "kvm", "module_setup": true }, "changed": false } 3.2 Ping模块:来测试远程主机的运行状态 [root@ansible-server ansible]# ansible client -m ping 192.168.200.189 | success >> { "changed": false, "ping": "pong" } 192.168.200.105 | success >> { "changed": false, "ping": "pong" } 192.168.200.107 | success >> { "changed": false, "ping": "pong" }

下载文档到电脑,查找使用更方便

文档的实际排版效果,会与网站的显示效果略有不同!!

需要 10 金币 [ 分享文档获得金币 ] 2 人已下载

下载文档