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

  • 相关阅读:
    猜数字游戏(补)
    团队项目五(项目回顾)
    项目回顾
    第二次阶段冲刺
    团队项目(任务三):第一次冲刺
    个人项目(一):新猜数字
    课后作业(一)
    团队任务二
    团队任务(一)
    课后作业(一)
  • 原文地址:https://www.cnblogs.com/zoulixiang/p/9395370.html
Copyright © 2011-2022 走看看