jiay 发表于 2018-1-2 13:41:07

晓风残梦

  一。 Ad-hoc命令简介
  1. 格式:ansible <host>
  2. option参数:
  -v:输出详细的执行过程, -vvv最详细的结果
  -i:指定inventory的路径
  -f:并发的线程数量,默认是5
  -m:调用的模块
  -u:指令执行的账号
  -b:调用sudo
  3. 场景使用:
  3.1 ansible all -f 5 -m ping
  3.2 ansible proxy -s -m command -a 'hostname' -vvv
  3.3 ansible web-list
  3.4 time ansible 10.21.40.61 -B 5 -P 2 -T 2 -m command -a 'sleep 20' -u root
  二。Ad-Hoc查看系统设置:
  1. ansible app -a 'df -h'
  2.ansible app -m shell -a 'free -m'
  三。 Ad-Hoc的并发特性:
  1.-f 参数实现多线程
  2. 并发数量为cpu核数的偶数倍,如 4core8GB的,最多配20个线程。
  四。Ad-Hoc的模块使用:
  1. 查询使用说明: ansible-doc
  1.1 ansible-doc -l
  1.2 ansible-doc yum
  2. 场景:
  2.1 安装redhat-lsb
  ansible apps -m yum -a 'name=redhat-lsb state=present'
  2.2 查看系统版本号:
  ansible apps -m command -a 'lsb_release -a'
  2.3 为所有机器安装ntp服务
  ansible apps -s -m yum -a 'name=ntp state=present'
  ansible apps -m service -a 'name=ntpd state=started enabled=yes'
  五。特定主机的变更
  1. --limit参数实现:
  ansible app -m command -a 'service ntpd status' --limit '192.168.0.2'
  2. 指定ip
  ansible 192.168.0.2 -m command -a 'service ntpd status'
  3. 用‘:’做分隔,多台:
  ansible '192.168.0.2:192.168.0.3' -m command -a 'service ntpd status'
  4. 通过‘*’,泛匹配
  ansible 192.168.0.2* -m command -a 'service ntpd status'
  六。用户及用户组管理
https://images2017.cnblogs.com/blog/75896/201711/75896-20171108114807184-1351918729.png
https://images2017.cnblogs.com/blog/75896/201711/75896-20171108114850184-1685122974.png
页: [1]
查看完整版本: 晓风残梦