ping模块:
ansible webservers -m service -a “name=httpd state=started enabled=yes”
启动 开机自启
查看是否能够通讯
cron script
yum模块
(latest安装最新版present 默认安装installed安装absent卸载remove卸载):
ansible webservers -m yum -a “name=httpd state=installed”
工具 指定的ip 选项 模块 选项 名字 状态(安装还是卸载‘’absent‘’)
ansible webservers -m yum -a “name=httpd start=started”
工具 指定的组(里面的指定的IP)指定模块 yum模块 选项
iptables模块:
ansible webservers -m service -a “name=iptables state=stopped enable=no ”
永久关闭
Shell模块 (可以支持shell的特殊符号):
ansible webservers -m shell -a “setenforce 0”
当前环境要执行的命令(关闭指定ip防火墙)
Command(默认)模块(不支持shell的特殊符号):
service模块
(started(启动) stopped(停止) restarted(重启) reloaded(重载))
file模块(用来创建文件、目录、链接文件)
path:必选项,定义文件/目录的路径 directory:如果目录不存在,创建目录
touch:如果文件不存在,则会创建一个新的文件,如果文件或目录存在,更新也修改时间
mode:定义文件/目录的权限
修改为600
src:要被链接的源文件的路径 dest:被链接到的路径
User模块(用来创建用户)
name:创建的用户名字state: 是创建还是删除。(present,absent),默认是创建
remove:删除用户家目录,默认为no
password:设置密码,密码必须是密文 Openssl passwd
shell: 指定用户登录的shell环境
groud模块(用来创建用户组)
ansible webservers -m groud -a “name=tom state=absent”
state:是创建还是删除。(present,absent)name:指定用户名
Copy模块(用来复制文件至目标主机)
src:文件在管理主机的据对路径或者相对路径 dest:将文件复制到目标主机的路径
backup:是否将目标主机的同名文件备份,默认为no
Unarchive模块(用来解压文件)
get_url模块(用于从http、ftp、https服务器上下载文件//url指定要下载的文的URL地址)
Sshd优化