uytr 发表于 2016-8-4 09:36:16

ansible基本使用教程

一、安装
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum installansible

二、基本使用
copy模块:
    目的:把主控端/root目录下的a.sh文件拷贝到到指定节点上
    命令:ansible all -m copy -a 'src=/root/a.sh dest=/tmp/'


file模块:
    目的:更改指定节点上/tmp/t.sh的权限为755,属主和属组为root
    命令:ansible all -m file -a "dest=/tmp/t.sh mode=755 owner=root group=root"

cron模块:
    目的:在指定节点上定义一个计划任务,每隔3分钟到主控端更新一次时间
    命令:ansible all -m cron -a 'name="custom job" minute=*/3 hour=* day=* month=* weekday=* job="/usr/sbin/ntpdate 172.16.254.139"'


group模块:
    目的:在所有节点上创建一个组名为nolinux,gid为2014的组
    命令:ansible all -m group -a 'gid=2014 name=nolinux'


user模块:
    目的:在指定节点上创建一个用户名为nolinux,组为nolinux的用户
    命令:ansible all -m user -a 'name=nolinux groups=nolinux state=present'

yum模块:
    目的:在指定节点上安装 lrzsz 服务
    命令:ansible all -m yum -a "state=present name=httpd"


service模块:
    目的:启动指定节点上的 puppet 服务,并让其开机自启动
    命令:ansible all -m service -a 'name=puppet state=restarted enabled=yes'


script模块:
    目的:在指定节点上执行/root/a.sh脚本(该脚本是在ansible控制节点上的)
    命令:ansible all -m script -a '/root/a.sh'


ping模块:
    目的:检查指定节点机器是否还能连通
    命令:ansible all -m ping



command模块:
    目的:在指定节点上运行hostname命令
    命令:ansible all -m command -a 'hostname'

raw模块:
    目的:在all节点上运行hostname命令
    命令:ansible all -m raw-a 'hostname|tee'

get_url模块:
    目的:将http://10.1.1.116/favicon.ico文件下载到指定节点的/tmp目录下
    命令:ansible all -m get_url -a 'url=http://10.1.1.116/favicon.ico dest=/tmp'




页: [1]
查看完整版本: ansible基本使用教程