ansible的script模块能够实现远程服务器批量运行本地的shell脚本。 脚本必须要有执行权限 准备lnp脚本 cd /opt wget http://www.xchinagroup.top/softdown/shell/lnp7.sh chmod +x /opt/lnp7.sh ansible nginx -m script -a "/opt/lnp7.sh" +++++++++++++++++++++++++++++++++++++++++++ file 模块 多用于创建目录、文件、授权 ansible nginx -m file -a "path=/opt mode=0400" #修改目录权限,同样也可以修改文件权限,以及属主。 path #指定远程主机 目录或文件 recurse #递归授权 recurse=yes state #状态 directory #在远端服务器上创建目录 touch #在远端服务器上创建文件 link #表示创建链接文件 mode #设置文件或目录权限 owner #设置文件或目录属主 group #设置文件或目录属组![]()
![]()
创建目录: ansible nginx -m file -a "path=/tmp/xyz state=directory" ansible nginx -m file -a "path=/tmp/xyz state=directory owner=www group=www mode=0400" 前提是,www用户以及 www 组 必须要在 被管理端服务器上存在。 递归授权目录权限: ansible nginx -m file -a "path=/tmp/xyz state=directory owner=www group=www mode=0400 recurse=yes"
创建文件: ansible nginx -m file -a "path=/tmp/xyz/yj.txt state=touch owner=www group=www mode=0400" 前提是,/tmp/syz目录 www 用户和组 必须要在被管理端服务器上存在。
创建软链接: ansible nginx -m file -a "src=/opt dest=/tmp/xx state=link"