zoukankan      html  css  js  c++  java
  • 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"
    }

  • 相关阅读:
    一位老司机开车20年后得到的26条教训
    H608B无线路由破解方法
    我们去工作到底为了什么?
    什么是”中国梦”?
    Cubieboard A10 安装Nand系统,配置nginx,php,mysql,samba详细教程
    早晚有一天,我们都会成为自己当初讨厌的人
    当下中国的十二种孤独
    终于见到全文了,太唯美了!
    想生男想生女 从科学角度为你解读
    如何找到板块中所有个股
  • 原文地址:https://www.cnblogs.com/pigwan7/p/8192078.html
Copyright © 2011-2022 走看看