Ansible模块知多少

Linux大全评论775 views阅读模式

之前在公司推广使用了ansible,这也使用一段时间了,分享下有关ansible模块的使用相关介绍。

ansible 默认提供了很多模块来供我们使用。在 Linux 中,我们可以通过 ansible-doc -l 命令查看到当前 ansible 都支持哪些模块,通过 ansible-doc  -s  模块名  又可以查看该模块有哪些参数可以使用。

下面介绍比较常用的几个模块:

copy模块
file模块
cron模块
group模块
user模块
yum模块
service模块
script模块
ping模块
command模块
raw模块
get_url模块
synchronize模块

Ansible和Docker的作用和用法  http://www.linuxidc.com/Linux/2014-11/109783.htm

Ansible批量搭建LAMP环境 http://www.linuxidc.com/Linux/2014-10/108264.htm

Ansible :一个配置管理和IT自动化工具  http://www.linuxidc.com/Linux/2014-11/109365.htm

Linux下安装部署Ansible http://www.linuxidc.com/Linux/2015-02/112774.htm

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"

执行效果:

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 10.1.1.113 -m user -a 'name=nolinux groups=nolinux state=present'

执行命令:

补充:删除用户示例

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'

执行效果:

企鹅博客
  • 本文由 发表于 2020年8月18日 14:11:45
  • 转载请务必保留本文链接:https://www.qieseo.com/224679.html

发表评论