zoukankan      html  css  js  c++  java
  • ansible自动化工具安装和简单使用

    ansible自动化工具安装和简单使用

    1.安装

    ansible依赖于Python 2.6或更高的版本、paramiko、PyYAML及Jinja2。

    2.1 编译安装

    解决依赖关系

    # yum -y install python-jinja2 PyYAML python-paramiko python-babel python-crypto

    # yum install ansible

    在node1(Master):
    # ssh-keygen -t rsa   
    # ssh-copy-id -i /root/.ssh/id_rsa.pub root@node2    
    # ssh-copy-id -i /root/.ssh/id_rsa.pub root@node3    
    # ssh-copy-id -i /root/.ssh/id_rsa.pub root@node5
    在node2 (slave):
    # ssh-keygen -t rsa   
    # ssh-copy-id -i /root/.ssh/id_rsa.pub root@node1    
    # ssh-copy-id -i /root/.ssh/id_rsa.pub root@node3    
    # ssh-copy-id -i /root/.ssh/id_rsa.pub root@node5

    配置文件(最下面添加)

    [root@web-test ~]# cat /etc/ansible/hosts 

    [web]
    172.17.71.213:2468

    远程传送文件
    ansible web -m copy -a "src=/root/1.txt dest=/root/"
    修改文件
    ansible web -m lineinfile -a 'path=/root/1.txt regexp="^12334" line="test text" '

     命令查看

    [root@web-test ~]# ansible web -m command -a "df -h"

    [root@web-test ~]# ansible web -m command -a "ls /usr/local"

    ping 命令使用

    ansible -m ping 'web'  

    ansible web -m ping

    ansible常用命令
    所有主机 all
    ansible all -m ping
    多个主机或IP用“:”隔开
    ansible mysql03.yu.net:mysql02.yu.net -m ping
    用通配符匹配
    ansible mysql*.yu.net -m ping

  • 相关阅读:
    获取URL的name值 getUrl(url,name) 传入url和key 得到key对应的value
    封装GetQueryString()方法来获取URL的value值
    判断设备
    RecyclerView 加点击事件
    SparseArray,SparseBooleanArray和SparseIntArray
    内存泄漏监测-LeakCanary
    StrictMode
    数据结构-线性结构
    程序设计语言基础-知识点
    数据结构-概念
  • 原文地址:https://www.cnblogs.com/zoulixiang/p/9395370.html
Copyright © 2011-2022 走看看