• ansible使用


    [root@x112 ~]# yum repolist
    [root@x112 ~]#ssh-keygen 
    [root@x112 ~]#ssh-copy-id 192.168.0.160
    [root@x112 ~]#ssh 192.168.0.160
    
    [root@x112 ~]# yum -y install ansible      #需要epel扩展源
    [root@x112 ~]# cat /etc/ansible/ansible.cfg
    
    添加模块信息,例如如下:
    [root@x112 ~]#  vim /etc/ansible/hosts 
    [webserver]
    192.168.0.160
    
    [root@x112 ~]# ansible  webserver -m shell -a 'systemctl stop firewalld'
    [root@web1 ~]# systemctl status firewalld.service 
    firewalld.service - firewalld - dynamic firewall daemon
       Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
       Active: inactive (dead) since Fri 2020-08-07 15:19:44 CST; 29s ago
    

      

    开启inventory
    [root@x112 yum.repos.d]# vim /etc/ansible/ansible.cfg
    inventory      = /etc/ansible/hosts
    
    
    
    [root@x112 yum.repos.d]# vim /etc/ansible/hosts
    [root@x112 yum.repos.d]# grep -Ev '^[$|#]' /etc/ansible/hosts
    [webserver]            #定义主机组的名称
    192.168.0.61           #主机组中的主机地址 
    192.168.0.62
    192.168.0.63
    192.168.0.64
    192.168.0.65
    [root@x112 yum.repos.d]#
    [root@x112 yum.repos.d]# ansible webserver --list-host
      hosts (5):
        192.168.0.61
        192.168.0.62
        192.168.0.63
        192.168.0.64
        192.168.0.65
    [root@x112 yum.repos.d]# ansible webserver -m ping 
    #命令格式,ansible  主机组名称   -m  模块名称   -a 模块参数
    
    [root@x112 yum.repos.d]# ansible webserver -m ping
    192.168.0.63 | UNREACHABLE! => {
        "changed": false, 
        "msg": "Failed to connect to the host via ssh: ssh: connect to host 192.168.0.63 port 22: No route to host", 
        "unreachable": true
    }
    192.168.0.65 | UNREACHABLE! => {
        "changed": false, 
        "msg": "Failed to connect to the host via ssh: ssh: connect to host 192.168.0.65 port 22: No route to host", 
        "unreachable": true
    }
    

      

      

  • 相关阅读:
    for..of与for..in
    吉凶与祸福之辩证
    console.log(0.2+0.4===0.6)// true or false??
    Javascripte的原型链之基础讲解
    Vue之九数据劫持实现MVVM的数据双向绑定
    Object的方法
    Javscript的函数链式调用基础篇
    Object.keys
    Object.prototype.hasOwnProperty与Object.getOwnPropertyNames
    call和apply还有bind
  • 原文地址:https://www.cnblogs.com/xiaofeng666/p/13453188.html
Copyright © 2020-2023  润新知