- Ansible自动化运维:技术与最佳实践
- 陈金窗 沈灿 刘政委编著
- 629字
- 2023-01-19 15:10:49
2.5 获取帮助信息
在Ansible 1.9.2版本中有8个主要的Ansible管理工具,每个管理工具都是一系列的模块、参数支持。随时可获取的帮助信息对了解掌握Ansible系统非常重要。对于Ansible每个工具,都可以简单地在命令后面加上-h或--help直接获取帮助。
例如,列出ansible-doc工具的支持参数。最主要的参数-l列出可使用的模块,-s列出某个模块支持的动作,如下所示:
[root@ansiblecontrol]# ansible-doc -h Usage: ansible-doc [options] [module...] Show Ansible module documentation Options: --version show program' s version number and exit -h, --help show this help message and exit -M MODULE_PATH, --module-path=MODULE_PATH Ansible modules/ directory -l, --list List available modules -s, --snippet Show playbook snippet for specified module(s) -v Show version number and exit
用ansible-doc -l列出Ansible系统支持的模块,Ansible安装后能够列出259个模块,如下所示
$ ansible-doc -l less 458 (POSIX regular expressions) Copyright (C) 1984-2012 Mark Nudelman less comes with NO WARRANTY, to the extent permitted by law. For information about the terms of redistribution, see the file named README in the less distribution. Homepage: http://www.greenwoodsoftware.com/less a10_server Manage A10 Networks AX/SoftAX/Thunder/vThunder... a10_service_group Manage A10 Networks AX/SoftAX/Thunder/vThunder... a10_virtual_server Manage A10 Networks AX/SoftAX/Thunder/vThunder... acl Sets and retrieves file ACL information. add_host add a host (and alternatively a group) to the ... airbrake_deployment Notify airbrake about app deployments alternatives Manages alternative programs for common comman... apache2_module enables/disables a module of the Apache2 webse... apt Manages apt-packages apt_key Add or remove an apt key ………
ansible-doc直接加模块名称,将显示该模块的描述和使用示例,如ansible-doc ping。每个模块都有一系列的动作,可以用ansible-doc -s+模块名称列出,如下面列出yum模块的动作:
$ ansible-doc -s yum less 458 (POSIX regular expressions) Copyright (C) 1984-2012 Mark Nudelman less comes with NO WARRANTY, to the extent permitted by law. For information about the terms of redistribution, see the file named README in the less distribution. Homepage: http://www.greenwoodsoftware.com/less - name: Manages pack age swith the I (yum) pac action: yum conf_file # The remote yum configuration file to use for the disable_gpg_check # Whether to disable the GPG checking of signatures disablerepo # ' Repoid' of repositories to disable for the insta enablerepo # ' Repoid' of repositories to enable for the instal list # Various (non-idempotent) commands for usage with name= # Package name, or package specifier with version, state # Whether to install (`present' , `latest' ), or remo update_cache # Force updating the cache. Has an effect only if s
另外,在Ansible调试自动化脚本时候经常需要获取执行过程的详细信息,可以在命令后面添加-v或-vvv得到详细的输出结果。如:
$ansible webservers -i inventory.cfg -m ping -vvv
最后别忘了经常浏览官方网站http://docs.ansible.com/,其中有详细的使用说明。