Ansible使用 (二)

远程命令模块

# 远程执行命令
ansible web -m command -a "ifconfig"

# 远程执行本机的脚本、其实是scp+shell,远程不会留下脚本
ansible web -m script -a "/root/aaa.sh"

# 远程执行 远端服务器脚本
ansible web -m script -a "/root/aaa.sh"

copy 模块

# 实现 主控端向远端拷贝文件,类似于scp
ansible web -m copy -a " src=/root/test.sh dest=/tmp/ owner=root group=root mode=0644"
-------
src 主机文件路径
dest 目标主机路径
owner group 所属和组
mode 是权限
+++++++++++++
如果只是修改远程权限,使用file模块
"path=/root/conf.ini owner=root group=root mode=0644"
+++++++++++++

stat 模块

# 获取远程文件的状态信息
# atime ctime mtime md5 uid gid等
ansible web -m stat  -a  "path=/root/test.conf"

get_url 模块

# 命令 远程主机去下载,下载到远程主机自己的路径下
ansible web -m get_url  -a  "url=http://www.baidu.com dest=/root/baidu.html mode=0440 force=yes"

yum 模块

ansible all -m yum -a "name=httpd state=latest disable_gpg_check=yes enablerepo=epel"
# --------
# name 包名
# state (Choices: present, installed, latest, absent, removed)[Default: present]
# disable_gpg_check:禁止gpg检查
# enablerepo:只启动指定的repo

占位
https://blog.csdn.net/qq_33468857/article/details/81750024

猜你喜欢

转载自blog.csdn.net/sunt2018/article/details/90902857