ansible(自动化运维中)——ansible常用模块

shell模块
#帮助
ansible-doc shell
#获取主机名
ansible webserver -m shell -a 'hostname' -o
#指定线程数(默认线程数是5)
ansible webserver -m shell -a 'hostname' -o -f 2
#部署apache
ansible host2 -m shell -a 'yum -y install httpd' -o
#查询系统负载
ansible host3 -m shell -a 'uptime' -o
复制模块
#帮助
ansible-doc copy
#将ansible/tmp/1.txt文件复制到webserver主机组的/tmp下并重命名为2.txt,并设置属主为root,数组为bin,赋予777权限
ansible webserver -m copy -a 'src=/tmp/1.txt dest=/tmp/2.txt owner=root group=bin mode=777' 

#'backup=yes'如果文件发生更改,会将之前的备份
ansible webserver -m copy -a 'src=/tmp/1.txt dest=/tmp/2.txt owner=root group=bin mode=777 backup=yes' 
用户模块
#帮助
ansible-doc user
#创建用户 
ansible webserver -m user -a 'name=pengge state=present'
#将密码加密
echo '512050951' | openssl passwd -1 -stdin
#修改密码
ansible webserver -m user -a 'name=qianfeng password="$1$XVzsJMDr$5wI4oUaQ.emxap6s.N272."'
#修改shell
ansible webserver -m user -a 'name=qianfeng shell=/sbin/nologin append=yes'
#删除用户
ansible webserver -m user -a 'name=qianfeng state=absent'
yum模块
#帮助 
ansible-doc yum 
#升级host1所有包
ansible host1 -m yum -a 'name="*" state=latest'
#host2安装http
ansible host2 -m yum -a 'name="httpd" state=latest'
服务模块
#帮助
ansible-doc service
#启动httpd
ansible host2 -m service -a 'name=httpd state=started'
#开机启动httpd
ansible host2 -m service -a 'name=httpd state=started enabled=yes'
#停止httpd
ansible host2 -m service -a 'name=httpd state=stopped'
#重启httpd
ansible host2 -m service -a 'name=httpd state=restarted'
#开机禁止启动
ansible host2 -m service -a 'name=httpd state=started enabled=no'
file模块
#帮助
ansible-doc file 
#在host1创建路径为/tmp/1.txt,并且赋予777权限的文件
ansible host1 -m file -a 'path=/tmp/1.txt mode=777 state=touch'
#在host1创建在/tmp/下的目录catalog,并赋予777权限
ansible host -m file -a 'path=/tmp/catalog mode=777 state=touch'
收集模块
#帮助
ansible-doc setup
#查询host3所有信息
ansible host3 -m setup
#查询host3的ipv4地址
ansible host3 -m setup -a 'filter=ansible_all_ipv4_addresses'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维-阿鹏

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值