常用模块
1.调试测试类
ping: ping一下远程主机,如果可以通,那么返回pong.
ansible all -m ping
debug:用于调试模块,只是简单的打印一些信息,像echo
ansible all -m debug
2.文件类
copy:从本地复制文件到远程节点.
ansible all -m copy -a "src=original-ks.cfg dest=/tmp/ owner=foo group=foo mode=0664" 设置文件权限
ansible all -m copy -a "src=original-ks.cfg dest=/tmp/ backup=yes" 备份节点上原来的文件
ansible all -m copy -a "src=/etc/sudoers dest=/etc/sudoers validate='visudo -cf %s'" 复制文件后验证操作
template:从本地复制文件到远程节点,并进行变量的替换.
file:设置文件属性
ansible all -m file -a "path=/tmp/original-ks.cfg owner=root group=root state=touch" 创建文件
ansible all -m file -a "src=/tmp/original-ks.cfg dest=/tmp/test1 owner=root group=root state=link" 软连接
ansible all -m file -a "path=/tmp/t2 owner=root group=root state=directory mode=0755" 创建目录
3.linux 常用操作
user:添加,删除,修改用户
ansible all -m user -a "name=johnd1 comment=johnd1 uid=1040 group=root" 创建用户johnd1 root组
ansible all -m user -a "name=johnd3 shell=/bin/bash groups=root,johnd2" 添加到两个组中
ansible all -m user -a "name=johnd3 state=absent remove=yes" 删除用户
yum:安装包
ansible all -m yum -a "name=httpd state=latest" 安装最新版本httpd
ansible all -m yum -a "name=httpd state=absent" 删除包
service 服务管理模块
ansible all -m service -a "name=httpd state=started"
ansible all -m service -a "name=httpd state=stopped"
ansible all -m service -a "name=httpd state=restarted"
ansible all -m service -a "name=httpd state=reloaded"
ansible all -m service -a "name=httpd enabled=yes"
firewalld
4.执行shell命令
shell
command