码迷,mamicode.com
首页 > 其他好文 > 详细

ansible常用模块

时间:2019-02-09 22:21:16      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:脚本   service   rip   path   删除用户   min   att   ali   stat   

ansible常用模块

安装:依赖于epel源

yum install ansible -y 
配置文件:/etc/ansible/ansible.cfg
Invertoory: /etc/ansible/hosts

 

如何查看模块帮助:

    ansible-doc -l
ansible-doc -s MODULE_NAME`

 

ansible命令应用基础

语法:ansible <host-pattern> [options]
-f forks: 启动的并发线程数
-m module_name: 要使用的模块
-a args: 模块特有的参数

 

ansible常用模块

command: 命令模块,默认模块,用于在远程执行命令
ansible all -a ‘date‘
cron:
*/10 * * * * /bin/echo hello linux
state:
present:
  #安装 ?ansible all -m cron -a ‘minute="*/10" job="/bin/echo hello linux" name="test cron_job" state=present‘
absent:
#移除 ?ansible all -m cron -a ‘minute="*/10" job="/bin/echo hello linux" name="test cron_job" state=absent‘
?ansible all -a "crontab -l"
user:
?
# 创建用户
? ansible all -m user -a ‘name="user1"‘
? cat /etc/passwd # 最后一行
?
# 删除用户
? ansible all -m user -a ‘name="user1" state="absent"‘
group:  
?
# 创建组
?
? ansible all -m group -a ‘name=mysql gid=306 system=yes‘
? cat /etc/group
?
# 删除组
?
? ansible all -m group -a ‘name=mysql gid=306 system=yes state=absent‘
copy:
?
# 复制文件 src定义本地源文件路径 dest定义远程主机路径(绝对路径)
?
? ansible all -m copy -a ‘src=/etc/fstab dest=/tmp/fstab.ansible owner=root mode=640‘
?
# content 生成内容的方式进行远程复制
?
? ansible all -m copy -a ‘content="你好崔建忠\n" dest=/tmp/test.ansible‘
file: # 设定文件属性
?
# 改变文件的属主属组
?
? ansible all -m file -a ‘owner=mysql group=mysql mode=644 path=/tmp/fstab.ansible‘
?
# link 创建文字符号链接
?
? ansible all -m file -a ‘path=/tmp/fstab.link src=/tmp/fstab.ansible state=link‘
ping:
?
# 测试主机是否能链接
?
? ansible all -m ping
?
?
service:
?
# 设置开机自启动,并且现在启动起来
?
? ansible all -m service -a ‘enabled=true name=httpd state=started‘
?
# 关闭某一个服务
?
? ansible all -m service -a ‘enabled=true name=httpd state=stopped‘
?
shell: 执行shell命令
? ansible all -m shell -a ‘hello ansible|passwd --stdin user1‘
?
script: 将本地脚本复制到远程主机并运行
? ansible all -m script -a ‘/root/test.sh‘
?
yum: 安装程序包
name=: 指明要安装的程序包,可以带上版本号
state=: present,latest表示安装,absent表示卸载
?
setup: 收集远程主机的facts
每个被管理节点在接收并且运行管理命令之前,会将自己主机相关的信息,如操作系统版本、ip地址等报告给远程的ansible主机;

 

ansible常用模块

标签:脚本   service   rip   path   删除用户   min   att   ali   stat   

原文地址:https://www.cnblogs.com/c040/p/10358062.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!