ansible(7)--ansible的file模块
1. file模块
功能:为被控端创建文件或目录,设定权限属性;
主要参数如下:
| 参数 | 说明 |
|---|---|
| path | 指定远程服务器的路径,也可以写成‘dest’,‘name’ |
| state | 状态,可以将值设定为directory表示创建目录,设定为touch表示创建文件,设定为link表示创建软连接,设定为hard表示创建硬连接,设定为absent表示删除目录文件或链接 |
| mode | 文件复制到远程并设定权限,默认file=644,directory=755 |
| owner | 文件复制到远程并设定属主,默认为root |
| group | 文件复制到远程并设定属组,默认为root |
| recurese | 递归修改 |
示例一:创建文件
/root/f1.sh,并设定属主、属组、权限:[root@xuzhichao ~]# ansible NginxWebs -m file -a 'path=/root/f1.sh owner=root group=root mode=755 state=touch'
192.168.20.23 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"dest": "/root/f1.sh",
"gid": 0,
"group": "root",
"mode": "0755",
"owner": "root",
"size": 0,
"state": "file",
"uid": 0
}
192.168.20.22 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"dest": "/root/f1.sh",
"gid": 0,
"group": "root",
"mode": "0755",
"owner": "root",
"size": 0,
"state": "file",
"uid": 0
}
示例二:修改上例中文件的属主属组为
xu:[root@xuzhichao ~]# ansible NginxWebs -m file -a 'path=/root/f1.sh owner=xu group=xu'
192.168.20.22 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"gid": 1000,
"group": "xu",
"mode": "0755",
"owner": "xu",
"path": "/root/f1.sh",
"size": 0,
"state": "file",
"uid": 1000
}
192.168.20.23 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"gid": 1000,
"group": "xu",
"mode": "0755",
"owner": "xu",
"path": "/root/f1.sh",
"size": 0,
"state": "file",
"uid": 1000
} [root@nginx03 ~]# ll /root/f1.sh
-rwxr-xr-x 1 xu xu 0 Aug 1 22:22 /root/f1.sh
示例三:创建目录
/root/test/,并设定属主、属组、权限[root@xuzhichao ~]# ansible NginxWebs -m file -a 'path=/root/test owner=root group=root mode=755 state=directory'
192.168.20.23 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"gid": 0,
"group": "root",
"mode": "0755",
"owner": "root",
"path": "/root/test",
"size": 6,
"state": "directory",
"uid": 0
}
192.168.20.22 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"gid": 0,
"group": "root",
"mode": "0755",
"owner": "root",
"path": "/root/test",
"size": 6,
"state": "directory",
"uid": 0
} [root@nginx03 ~]# ll /root/test/ -d
drwxr-xr-x 2 root root 6 Aug 1 22:26 /root/test/
示例四:为
/root/f1.sh创建软链接文件/root/f1.sh.link:[root@xuzhichao ~]# ansible NginxWebs -m file -a 'src=/root/f1.sh dest=/root/f1.sh.link state=link'
192.168.20.23 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"dest": "/root/f1.sh.link",
"gid": 0,
"group": "root",
"mode": "0777",
"owner": "root",
"size": 11,
"src": "/root/f1.sh",
"state": "link",
"uid": 0
}
192.168.20.22 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"dest": "/root/f1.sh.link",
"gid": 0,
"group": "root",
"mode": "0777",
"owner": "root",
"size": 11,
"src": "/root/f1.sh",
"state": "link",
"uid": 0
} [root@nginx03 ~]# ll /root/f1.sh*
-rwxr-xr-x 1 xu xu 0 Aug 1 22:22 /root/f1.sh
lrwxrwxrwx 1 root root 11 Aug 1 22:28 /root/f1.sh.link -> /root/f1.sh
示例五:删除以上示例中创建的目录和文件:
[root@xuzhichao ~]# ansible NginxWebs -m file -a 'path=/root/f1.sh.link state=absent'
192.168.20.23 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"path": "/root/f1.sh.link",
"state": "absent"
}
192.168.20.22 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"path": "/root/f1.sh.link",
"state": "absent"
}
[root@xuzhichao ~]# ansible NginxWebs -m file -a 'path=/root/f1.sh state=absent' [root@xuzhichao ~]# ansible NginxWebs -m file -a 'path=/root/test state=absent'
示例六:也可以删除一级目录(挂载点),会报错,但是可以清楚数据:
[root@localhost /data] #ansible app -m file -a 'dest=/data/ state=absent'
192.168.169.130 | FAILED! => {
"changed": false, <==报错 [root@localhost /data] #ansible app -a 'ls -l /data/'
total 0 <==数据已经清空
示例七:递归授权目录,类似于
-R的作用:[root@manger ~]# ansible webservers -m file -a "path=/tmp/foo state=directory owner=root group=root mode=777 recurse=yes"
ansible(7)--ansible的file模块的更多相关文章
- ansible 的file 模块
创建.修改.删除文件或者目录: file模块 file模块常用的几个参数:state.path.src.dest.mode.owner.group.name.recurse state后面跟的参数: ...
- ansible使用file模块管理受控机的目录与文件(ansible2.9.5)
一,ansible的file模块的用途 file 模块实现对文件的基本操作. 例如: 创建文件或目录 删除文件或目录 修改文件权限等 说明:刘宏缔的架构森林是一个专注架构的博客,地址:https:// ...
- ansible学习系列2-ansible常用模块使用
1. 查看支持的模块 [root@localhost ~]# ansible-doc -l 这里我们看下ansible的支持的模块个数 [root@localhost ~]# ansible-doc ...
- ansible学习基础知识和模块(一)
基础知识补充: 常用自动化运维工具 Ansible:使用python来开发的,无需设置Agentless(代理),一般管理几百台.与ssh的方式也不一样,ssh是基于c/s模式(客户端+服务器)来使用 ...
- Ansible安装部署以及常用模块详解
一. Ansible 介绍Ansible是一个配置管理系统configuration management system, python 语言是运维人员必须会的语言, ansible 是一个基于py ...
- ansible环境部署及常用模块总结 - 运维笔记
一. Ansible 介绍Ansible是一个配置管理系统configuration management system, python 语言是运维人员必须会的语言, ansible 是一个基于py ...
- Ansible安装部署及常用模块详解
Ansible命令使用 Ansible语法使用ansible <pattern_goes_here> -m <module_name> -a <arguments> ...
- Ansible基础配置与常用模块使用
环境介绍: Ansible服务端IP:192.168.2.215 Ansible客户端IP:192.168.2.216.192.168.2.218.192.168.2.113 一.创建Ansibl ...
- Ansible 开发调试 之【模块调试】
本地调试 需要安装jinja2 库 yum -y install python-jinja2 使用官方提供的测试脚本调试 git clone git://github.com/ansible/ansi ...
- 10.Python之Ansible自动化运维常用模块
Ansible中文权威文档:http://www.ansible.com.cn/docs/ Ansible从入门到精通:https://www.bilibili.com/video/av3361175 ...
随机推荐
- 数据库锁起来了,把事务清掉sql
select concat('kill ',id,';') from information_schema.`PROCESSLIST` where state !='executing' 将上述代码执 ...
- #NTT,DP#U138580 简单的打击
题目 给出两个等长的序列\(a,b\), 重排序列\(b\),使得\(a+b\)众数出现的次数最多 分析 设\(f[i]\)表示众数为\(i\)的贡献,那么 \(f[i]=\sum_{j<i}m ...
- Go 实战|使用 Wails 构建轻量级的桌面应用:仿微信登录界面 Demo
概述 本文探讨 Wails 框架的使用,从搭建环境到开发,再到最终的构建打包,本项目源码 GitHub 地址:https://github.com/mazeyqian/go-run-wechat-de ...
- 网络组件axios可以在OpenHarmony上使用了
什么是axios 上古浏览器页面在向服务器请求数据时,因为返回的是整个页面的数据,页面都会强制刷新一下,这对于用户来讲并不是很友好.并且我们只是需要修改页面的部分数据,但是从服务器端发送的却是整个页面 ...
- C#利用自动化接口编写OPC客户端,OPC Client,源码直接放网盘
引用:https://www.cnblogs.com/flh1/p/12409266.html 链接: https://pan.baidu.com/s/1Vs08c7qjShEc9GQ8dvCkdg ...
- Linux 编译 libjpeg-9e
jpeg的库有两个:一个是官方的 libjpeg 还有一个是 libjpeg-turbo JPEG库(libjpeg-turbo):https://libjpeg-turbo.org/ Libjpe ...
- std::thread 四:异步(async)
*:如果 std::async 中传递参数 std::lunnch::deferred ,就需要等待调用 get() 或者 wait() 才会执行,并且代码非子线程运行,而是在主线程中执行 #incl ...
- centos环境Jenkins配置war包Tomcat
末尾有软件安装包,自行下载(centos环境) centos JDK Jenkins maven tomcat git myslq nginx 7.9 11.0.19 2.418 3.8.1 9.0. ...
- Vue3实现图片滚轮缩放和拖拽
在项目开发中遇到一个需求: 1:用鼠标滚轮可对图片进行缩放处理 2:点击按钮可对图片进行缩放处理 3:可对图片进行拖拽处理 我在开发中通过自己实现与百度查看优秀的铁子进行了两种类型的使用 <te ...
- T-SQL中执行存储过程与C#执行同样操作的比较
1 exec sp_executesql N"UPDATE [dbo].[Courses] 2 SET [Title] = @0 3 WHERE (([CourseID] = @1) AND ...