• Ansible学习 Patterns


      Ansible中ad-hoc命令格式如下:ansible <pattern_goes_here> -m <module_name> -a <arguments>,Patterns用来指定目标主机,对于Patterns的用法如下

    inventory文件如下:

    [test]
    192.168.144.129
    192.168.144.130

    [test1]
    192.168.144.129

    [test2]
    192.168.144.130

    1、all代表inventory文件中的所有主机

    [root@client01 ansible]# ansible all -m ping
    192.168.144.130 | SUCCESS => {
    "changed": false,
    "failed": false,
    "ping": "pong"
    }
    192.168.144.129 | SUCCESS => {
    "changed": false,
    "failed": false,
    "ping": "pong"
    }

    2、IP或IP通配主机名

    [root@client01 ansible]# ansible 192.168.144.129 -m ping
    192.168.144.129 | SUCCESS => {
    "changed": false,
    "failed": false,
    "ping": "pong"
    }
    [root@client01 ansible]#
    [root@client01 ansible]# ansible 192.168.144.* -m ping
    192.168.144.129 | SUCCESS => {
    "changed": false,
    "failed": false,
    "ping": "pong"
    }
    192.168.144.130 | SUCCESS => {
    "changed": false,
    "failed": false,
    "ping": "pong"
    }

    3、一个组

    [root@client01 ansible]# ansible test -m ping
    192.168.144.129 | SUCCESS => {
    "changed": false,
    "failed": false,
    "ping": "pong"
    }
    192.168.144.130 | SUCCESS => {
    "changed": false,
    "failed": false,
    "ping": "pong"
    }

    4、多个组同时操作

    [root@client01 ansible]# ansible test1:test2 -m ping
    192.168.144.129 | SUCCESS => {
    "changed": false,
    "failed": false,
    "ping": "pong"
    }
    192.168.144.130 | SUCCESS => {
    "changed": false,
    "failed": false,
    "ping": "pong"
    }

    5、在组中选择对应编号的主机

    [root@client01 ansible]# ansible test[0] -m ping
    192.168.144.129 | SUCCESS => {
    "changed": false,
    "failed": false,
    "ping": "pong"
    }

    6、主机和组同时操作

    [root@client01 ansible]# ansible 192.168.144.129:test2 -m ping
    192.168.144.130 | SUCCESS => {
    "changed": false,
    "failed": false,
    "ping": "pong"
    }
    192.168.144.129 | SUCCESS => {
    "changed": false,
    "failed": false,
    "ping": "pong"
    }

  • 相关阅读:
    学习笔记Jmail收发邮件
    ModalPopup
    学习笔记:UpdatePanel控件
    转AjaxControlToolkit的安装与使用详解
    转linq中的Single()、First()、Take(1) LINQ 标准的查询操作符 排序 orderby、thenby、Take
    转Global.asax文件
    转<%%>、<%=%>、<%$%>、<%@%>的区别
    C++文件包含处理—#include
    GISer学习之道(转载)
    OSG中的示例程序简介
  • 原文地址:https://www.cnblogs.com/pigwan7/p/8192078.html
Copyright © 2020-2023  润新知