ansible教程:ansible的简单使用

本章通过几个例子来简单说明ansible怎么使用


ansible的第一个demo

第一个demo可以通过ping模块去ping某个主机,ping命令如下:

ansible all -m ping

执行结果如下:

[root@ecs-3f37-0003 ~]# ansible all -m ping
192.168.1.39 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    }, 
    "changed": false, 
    "ping": "pong"
}

ansible-doc 命令

ansible有很多内置模块,可以使用ansible-doc -l查看ansbile有哪些模块:

ansible-doc  -l

执行结果如下:

[root@ecs-3f37-0003 ~]# ansible-doc  -l
fortios_router_community_list                                 Configure community list...
azure_rm_devtestlab_info                                      Get Azure DevTest Lab fa...
ecs_taskdefinition                                            register a task definiti...
avi_alertscriptconfig                                         Module for setup of Aler...
tower_receive                                                 Receive assets from Ansi...
netapp_e_iscsi_target                        

ansible-doc -s查看模块的详细用法

ansible-doc -s 后跟模块名,可以参看模块的详细用法,如查看ping模块的用法:

[root@ecs-3f37-0003 ~]# ansible-doc -s ping
- name: Try to connect to host, verify a usable python and return `pong' on success
  ping:
      data:                  # Data to return for the `ping' return value.  If this
                               parameter is set to `crash',
                               the module will cause an
                               exception.

小结

更多ansible的使用,见后面的章节