bco 发表于 2018-1-2 23:25:10

ansible基本操作

  ansible优点:redhat自带工具,可通过rpm或yum直接安装;客户端免安装;操作通过ssh验证操作;可以通过自定义hosts文件对可操作主机进行分类,方便批量操作
  #ansible操作格式,默认hosts文件为/etc/ansible/hosts,默认用户名为root
  ansible [ -i hosts文件 ] 主机名、组名、域名 [ -u 用户名 ] -m 模块名 [ -k ]
  #hosts文件格式,默认路径为/etc/ansible/hosts

  #默认格式 IP:PORT ansible_ssh_user=jdhw_001 ansible_ssh_port=3022 ansible_ssh_pass='123456'
  127.0.0.1:3022  #定义IP + PORT,默认端口为22
  192.168.3.  #表示3.1 -- 3.10十台主机
  www.jintian.com
  db-.jintian.com
  #定义针对组的ssh用户、端口、密码等配置,该配置优先级比组内配置的要高(个人感觉不怎么合理)

  ansible_ssh_user=jdhw_001
  ansible_ssh_port=3022
  ansible_ssh_pass='123456'
  #对所有主机ping操作,all代表hosts下所有主机,-k输入指定用户的密码,-k通过验证后再次操作短时内可以不用再输入密码
  ansible all -u jdhw_001 -m ping -k
  SSH password:
  127.0.0.1 | SUCCESS => {
  "changed": false,
  "ping": "pong"
  #批量执行脚本
  ansible -i aa.hosts all -u jdhw_001 -m command -a 'sh /scripts/shell/echo_hello.sh'
  127.0.0.1 | SUCCESS | rc=0 >>
  hello
页: [1]
查看完整版本: ansible基本操作