ansible server -m command -a 'systemctl restart httpd'
shell:和command模块相似,用shell执行命令
ansible server -m shell -a 'systemctl start httpd'
scrip:在远程主机上执行ansible主机上的脚本,且不需要将脚本复制到被执行的远程主机上
ansible server -m script -a '/root/Shell/script.sh'
copy:从主控端复制文件到客户端
ansible server -m copy-a 'src=/root/guoqiang.sh dest=/root/'# backup=yes:备份
ansible all -m copy-a 'content="hello\nthanks\n" dest=/root/guoqiang.sh'# content:生成自定义内容写入guoqiang.sh文件中
fetch:从客户端取文件主控端,与copy相关,目前可以先tar
nsible server -m fetch -a 'src=/root/guoqiang.sh dest=/data'
file:设置文件属性
ansible server -m file -a 'path=/root/guoqiang.sh mode=777'# 创建一个新的空文件
ansible server -m file -a 'path=/data/readme.sh state=touch'# 创建一个文件夹
ansible server -m file -a 'path=/data state=directory'# 生成软件链接文件
ansible server -m file -a 'src=/etc/fstab path=/data/fstab.link state=link'# 删除一个文件
ansible server -m file -a 'path=/data/readme.sh state=absent'# 删除一个文件夹
ansible server -m file -a 'path=/data state=absent'# 删除一个软连接文件
ansible server -m file -a 'path=/fstab.link state=absent'
hostname:管理主机名
ansible 172.16.7.130 -m hostname -a 'name=ansible-slave'#将172.16.7.130节点的主机名修改为ansible-slave
yum:管理包
# 安装
ansible server -m yum -a 'name=httpd state=installed'# 查看已经安装的包
ansible server -m yum -a 'list=installed'# 卸载
ansible server -m yum -a 'name=httpd state=removed'
service:管理服务
ansible server -m service -a 'name=httpd state=started enabled=yes'#启动:started#重启:restarted#停止:stopped#开机自启:enabled=yes#取消开机自启:enabled=no