一 点睛
Ansible提供了非常丰富的功能模块,包括Cloud(云计算)、 Commands(命令行)、Database(数据库)、Files(文件管理)、 Internal(内置功能)、Inventory(资产管理)、Messaging(消息队列)、Monitoring(监控管理)、Net Infrastructure(网络基础服务)、Network(网络管理)、Notification(通知管理)、Packaging(包管 理)、Source Control(版本控制)、System(系统服务)、Utilities(公 共服务)、Web Infrastructure(Web基础服务),等等。 模块默认存储目录为/usr/share/ansible/,存储结构以模块分类名作为目 录名,模块文件按分类存放在不同类别目录中。
命令行调用模块格式: ansible<pattern_goes_here(操作目标)>-m<module_name(模块名)>a<module_args(模块参数)>,其中默认的模块名为command,即“-m command”可省略。
获取远程webservers组主机的uptime信息格式的命令如下:
[root@localhost ansible]# ansible webservers -m command -a uptime
192.168.0.101 | SUCCESS | rc=0 >>
21:06:03 up 1:32, 4 users, load average: 0.00, 0.01, 0.05
192.168.0.102 | SUCCESS | rc=0 >>
21:06:05 up 1:26, 4 users, load average: 0.16, 0.05, 0.06
以上命令等价于:
[root@localhost ansible]# ansible webservers -a uptime