Ansible基础命令

常用模块练习:
src:  source 源文件=取目标文件,目标文件所在路径
dest:  destination:目的文件,存放到ansible目标路径

文件管理模块:
“取”模块fetch
ansible 192.168.10.30  -m fetch -a 'src=/etc/hosts dest=/root' 

复制文件copy
ansible 192.168.10.30 -m copy -a 'src=/root/aa dest=/opt/bb' 

file模块
删除文件:ansible 192.168.10.10 -m file -a 'path=/opt/bb state=absent'
创建新文件,权限是777:ansible 192.168.10.10 -m file -a 'path=/opt/dd state=touch mode=777'
创建文件夹,权限是777:ansible 192.168.10.10 -m file -a 'path=/opt/cc state=directory mode=777'

user用户管理模块
创建用户:ansible 192.168.10.10 -m user -a 'name=aa group=root state=present'
删除用户:ansible 192.168.10.10 -m user -a 'name=aa group=root state=absent'

shell命令行模块(类似于command,但是shell支持特殊符号)
查看目标主机是否有aa用户:
ansible 192.168.10.10 -m shell -a 'cat /etc/passwd |grep aa'

service 服务模块
为受管主机安装httpd
(确保受管主机能够安装httpd,光碟源可以安装httpd)
ansible 192.168.10.10 -m yum -a 'name=httpd state=present'
ansible 192.168.10.10 -m service -a 'name=httpd state=started enabled=true'
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值