ansible常用模块模块知多少

Ansible模块知多少_百度知道aaao 的BLOG
用户名:aaao
文章数:77
评论数:335
访问量:170964
注册日期:
阅读量:5863
阅读量:12276
阅读量:343852
阅读量:1044608
51CTO推荐博文
& & & &之前在公司推广使用了ansible,这也使用一段时间了,分享下有关ansible模块的使用相关介绍& & & &ansible 默认提供了很多模块来供我们使用。在 Linux 中,我们可以通过 ansible-doc&-l 命令查看到当前 ansible 都支持哪些模块,通过&ansible-doc&&-s&&模块名 &又可以查看该模块有哪些参数可以使用。& & & &下面介绍比较常用的几个模块:copy模块
service模块
script模块
command模块
get_url模块
synchronize模块copy模块:& & 目的:把主控端/root目录下的a.sh文件拷贝到到指定节点上& & 命令:ansible 10.1.1.113 -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"& & 执行效果:650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url(&/e/u261/lang/zh-cn/images/localimage.png&) no-border:1px solid #" alt="spacer.gif" />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'& & 执行效果:650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url(&/e/u261/lang/zh-cn/images/localimage.png&) no-border:1px solid #" alt="spacer.gif" />user模块:& &&目的:在指定节点上创建一个用户名为nolinux,组为nolinux的用户& & 命令:ansible 10.1.1.113 -m user -a 'name=nolinux groups=nolinux state=present'& & 执行命令:补充:删除用户示例650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url(&/e/u261/lang/zh-cn/images/localimage.png&) no-border:1px solid #" alt="spacer.gif" />yum模块:& &&目的:在指定节点上安装 lrzsz 服务& & 命令:ansible all -m yum -a&"state=present name=httpd"& & 执行效果:service模块:& &&目的:启动指定节点上的&puppet 服务,并让其开机自启动& & 命令:ansible 10.1.1.113 -m service -a 'name=puppet state=restarted enabled=yes'& & 执行效果:650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url(&/e/u261/lang/zh-cn/images/localimage.png&) no-border:1px solid #" alt="spacer.gif" />script模块:& & 目的:在指定节点上执行/root/a.sh脚本(该脚本是在ansible控制节点上的)& & 命令:ansible 10.1.1.113 -m script -a '/root/a.sh'& & 执行效果:650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url(&/e/u261/lang/zh-cn/images/localimage.png&) no-border:1px solid #" alt="spacer.gif" />ping模块:& & 目的:检查指定节点机器是否还能连通& & 命令:ansible 10.1.1.113 -m ping& & 执行效果:command模块:& & 目的:在指定节点上运行hostname命令& & 命令:ansible 10.1.1.113 -m command -a 'hostname'& & 执行效果:650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url(&/e/u261/lang/zh-cn/images/localimage.png&) no-border:1px solid #" alt="spacer.gif" />raw模块:& & 目的:在10.1.1.113节点上运行hostname命令& & 命令:ansible 10.1.1.113 -m raw-a 'hostname|tee'& & 执行效果:get_url模块:& & 目的:将文件下载到指定节点的/tmp目录下& & 命令:ansible 10.1.1.113 -m get_url -a 'url=&dest=/tmp'& & 执行效果:synchronize模块:& & 目的:将主控方/root/a目录推送到指定节点的/tmp目录下& & 命令:ansible 10.1.1.113 -m synchronize -a 'src=/root/a dest=/tmp/ compress=yes'& & 执行效果:delete=yes & 使两边的内容一样(即以推送方为主)compress=yes &开启压缩,默认为开启--exclude=.git &忽略同步.git结尾的文件由于模块,默认都是推送push。因此,如果你在使用拉取pull功能的时候,可以参考如下来实现mode=pull & 更改推送模式为拉取模式& & 目的:将10.1.1.113节点的/tmp/a目录拉取到主控节点的/root目录下& & 命令:ansible 10.1.1.113 -m synchronize -a 'mode=pull src=/tmp/a dest=/root/'& & 执行效果:& & & &由于模块默认启用了archive参数,该参数默认开启了recursive, links, perms, times, owner,group和-D参数。如果你将该参数设置为no,那么你将停止很多参数,比如会导致如下目的递归失败,导致无法拉取其它相关的参数解释:dest_port=22&&&&#&指定目的主机的ssh端口,ansible配置文件中的&ansible_ssh_port&变量优先级高于该&dest_port&变量
rsync_path&&&&&&#&指定&rsync&命令来在远程服务器上运行。这个参考rsync命令的--rsync-path参数,--rsync-path=PATH&&&&&#&指定远程服务器上的rsync命令所在路径信息
rsync_timeout&&&#&指定&rsync&操作的&IP&超时时间,和rsync命令的&--timeout&参数效果一样OK!& & & &以上暂且列举这些日常运维中经常会用到的一些模块,更多的模块信息后期会继续完善,大家也可以去官网查看更多的信息。& & & &官网地址:本文出自 “” 博客,请务必保留此出处
了这篇文章
类别:┆阅读(0)┆评论(0)
00:06:40 14:08:08 14:22:02 14:37:16 17:52:12 19:51:06&&国之画&&&& &&
版权所有 京ICP备号-2
迷上了代码!

我要回帖

更多关于 ansible script模块 的文章

 

随机推荐