常用模块练习:
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'
1292

被折叠的 条评论
为什么被折叠?



