zoukankan      html  css  js  c++  java
  • 【ansible】 笔记 (2)

    先使用 ansible-doc 获取帮助文档

    [root@localhost ~]# ansible-doc ping   
    > PING    (/usr/lib/python2.7/site-packages/ansible-2.3.0-py2.7.egg/ansible/modules/system/ping.py)
    
      A trivial test module, this module always returns `pong' on successful contact. It does not make sense in
      playbooks, but it is useful from `/usr/bin/ansible' to verify the ability to login and that a usable python is
      configured. This is NOT ICMP ping, this is just a trivial test module.
    
    EXAMPLES:
    # Test we can logon to 'webservers' and execute python with json lib.
    ansible webservers -m ping
    
    
    MAINTAINERS: Ansible Core Team, Michael DeHaan
    
    METADATA:
            Status: ['stableinterface']
            Version: 1.0
            Supported_by: core

    命令格式  Usage: ansible <host-pattern> [options]    

    • 显示 hosts 
    [root@localhost ~]# ansible all --list-hosts
      hosts (2):
        192.168.34.129
        192.168.34.130
    [root@localhost ~]# ansible webserver --list-hosts
      hosts (2):
        192.168.34.129
        192.168.34.130
    [root@localhost ~]# ansible 192.168.34.129:192.168.34.130 --list-hosts
      hosts (2):
        192.168.34.129
        192.168.34.130
    • 指定 inventory(hosts) 执行命令,使用 ansible -m 指定模块 -a 指定参数 -o 单行输出
    [root@localhost ~]# ansible  all -m ping                      
    192.168.34.130 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.34.129 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    [root@localhost ~]# ansible  webserver  -m ping    
    192.168.34.129 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.34.130 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    [root@localhost ~]# ansible  192.168.34.129  -m ping           
    192.168.34.129 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    [root@localhost ~]# ansible  192.168.34.129:192.168.34.130  -m ping 
    192.168.34.129 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    192.168.34.130 | SUCCESS => {
        "changed": false, 
        "ping": "pong"
    }
    [root@localhost ~]# ansible  192.168.34.129:192.168.34.130  -m command -a uptime -o
    192.168.34.129 | SUCCESS | rc=0 | (stdout)  05:08:05 up  1:53,  2 users,  load average: 0.08, 0.13, 0.13
    192.168.34.130 | SUCCESS | rc=0 | (stdout)  05:08:04 up  1:54,  2 users,  load average: 0.14, 0.10, 0.09
    • -m 默认模块是 command,这里可以忽略。同时我们可以自己编写脚本指定“动态 inventory”,具体的写法请自行百度。这个脚本需要支持两个参数, --list/-l  和 --host/-H,并且返回 json 格式的数据。

    • 需要注意的是如果“被控机”开启了 selinux,则在使用 copy 模块时需要在“被控机”上安装  libselinux-python,才能保证正常执行 copy 模块
  • 相关阅读:
    Android 2.2 r1 API 中文文档系列(11) —— RadioButton
    Android API 中文 (15) —— GridView
    Android 中文 API (16) —— AnalogClock
    Android2.2 API 中文文档系列(7) —— ImageButton
    Android2.2 API 中文文档系列(6) —— ImageView
    Android 2.2 r1 API 中文文档系列(12) —— Button
    Android2.2 API 中文文档系列(8) —— QuickContactBadge
    [Android1.5]TextView跑马灯效果
    [Android1.5]ActivityManager: [1] Killed am start n
    Android API 中文(14) —— ViewStub
  • 原文地址:https://www.cnblogs.com/lxmhhy/p/6506296.html
Copyright © 2011-2022 走看看