您的位置:首页 > 其它

ansible自动化管理服务常用模块及命令语法

2020-06-09 04:57 134 查看

一、ansible命令使用语法:
ansible 主机名称/主机组名称/主机地址信息/all -m(指定应用的模块信息) 模块名称 -a(指定动作信息) “执行什么动作”
例如:查看172.16.1.31的主机名

二、查看帮助
1、可在命令行使用ansible-doc module_name(模块名),查看模块的参数和详细信息

2、官网查看:
docs.ansible.org
1)模块索引

2)这里是所有模块的分类,点击命令模块分类


现在来对比一下命令行查看和官网查看:查看command
命令行:


官网:

可见一样!

三、常用模块总结
命令类型模块: command; shell; script

文件类型模块:copy,file
常用参数:copy: src,dest,backup=(yes,no),content,group,owner,mode
file: path,recurse,state=(directory,touch,link/hard,absent),group,owner,mode

安装软件模块:yum
常用参数:name,state=(installed/persent,removed/absent,latest)

启动服务模块:service
常用参数:name,state=(started,stopped,restarted,reloaded),enabled=yes/no

定时任务模块:cron

磁盘挂载模块:mount
常用参数:src,path,fstype,state=(present/mounted,absent/unmounted)

用户管理模块:user,group
常用参数user: name,uid,group,groups,password,shell,create_home=(yes/no)
常用参数group: name,gid,state=(absent,present)

压缩解压模块:unarchive archive
常用参数unarchive: src,dest,owner/group,mode,creates,copy=(yes/no)
list_files=(yes/no)

四、演示
简单测试一下把受控端backup /root/ysx02.txt复制到backup的/tmp目录下


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: