ansible ad hoc常用模块(copy、file、yum、service、user)

一、实验环境

server5:172.25.6.5  管理主机
server6:172.25.6.6
server7:172.25.6.7
server8:172.25.6.8
要保证server虚拟机环境纯净,安装虚拟机步骤详细见: https://blog.csdn.net/lcqrehl/article/details/107832183

二、Ansible Ad-Hoc命令集

ansible-doc -l   #显示所有可用模块

ansible-doc yum  #获取yum模块帮助,需要什么模块就在后面加,例如copy service等等

ansible的常用模块

1.copy模块

ansible test -m copy -a "src=/etc/passwd   dest=/mnt"  #-m调用模块,-a参数
#命令行表示在管理主机server5远程复制一个passwd文件到server6的/mnt,(因为test组下是server6)源路径是/etc/ 目的路径是/mnt 

 

2.file模块

ansible test -m file -a "dest=/etc/httpd/conf/httpd.conf mode=600 owner=devops group=root"    #修改文件权限和属性
ansible test -m file -a "dest=/mnt/westos mode=755 owner=root group=root state=directory"   #递归属性

3.yum模块

ansible test -m yum -a "name=httpd state=present" #下载httpd,
ansible test-m yum -a "name=httpd state=absent"  #卸载httpd

 下载httpd

server5中执行远程在server6上安装httpd服务

卸载httpd

4.service模块

 ansible test -m service -a "name=httpd state=started"   #打开httpd服务
 ansible test -m service -a "name=httpd state=restarted" #重启httpd服务
 ansible test -m service -a "name=httpd state=stopped"   #停止httpd服务

执行以上命令后,server6 的httpd打开

执行以上命令后,server6 的httpd服务关闭

5.user模块

ansible test -m user -a "name=lcq password=<加密密码>"
ansible test -m user -a "name=lcq state=absent remove=yes" 

6.mysql_user模块

ansible prod -m mysql_user -a "login_user=root name=wxh password=testpass priv='*.*:select' host='%' state=present"   #远程主机需要安装MySQL-python

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值