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

      

      

  • 相关阅读:
    Shiro理解与总结
    spark教程(14)-共享变量
    Hive 教程(十)-UDF
    multivariate_normal 多元正态分布
    windows 安装 python 踩坑记录
    EM 算法(三)-GMM
    EM 算法(二)-KMeans
    EM 算法(一)-原理
    sklearn-GDBT
    集成学习-Boosting 模型深度串讲
  • 原文地址:https://www.cnblogs.com/xiaofeng666/p/13453188.html
Copyright © 2011-2022 走看看