Ansible学习笔记4

file模块:

file模块用于对文件相关的操作(创建、删除、属性修改、软链接等)touch是创建。

[root@localhost ~]# ansible group1 -m file -a "path=/tmp/111 state=touch"
192.168.17.105 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"dest": "/tmp/111","gid": 0,"group": "root","mode": "0644","owner": "root","size": 0,"state": "file","uid": 0
}
192.168.17.106 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"dest": "/tmp/111","gid": 0,"group": "root","mode": "0644","owner": "root","size": 0,"state": "file","uid": 0
}
[root@localhost ~]# ansible group1 -m file -a "path=/tmp/111 state=touch owner=ftp group=daemon mode=777"
192.168.17.105 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"dest": "/tmp/111","gid": 2,"group": "daemon","mode": "0777","owner": "ftp","size": 0,"state": "file","uid": 14
}
192.168.17.106 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"dest": "/tmp/111","gid": 2,"group": "daemon","mode": "0777","owner": "ftp","size": 0,"state": "file","uid": 14
}

创建目录,并更改权限:directory:

[root@localhost ~]# ansible group1 -m file -a "path=/test/aaa/bbb state=directory mode=777"
192.168.17.106 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"gid": 0,"group": "root","mode": "0777","owner": "root","path": "/test/aaa/bbb","size": 6,"state": "directory","uid": 0
}
192.168.17.105 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"gid": 0,"group": "root","mode": "0777","owner": "root","path": "/test/aaa/bbb","size": 6,"state": "directory","uid": 0
}
[root@agent1 tmp]# cd /test/aaa/bbb
[root@agent1 bbb]# ll
total 0
[root@agent1 bbb]# pwd
/test/aaa/bbb

删除文件:absent

[root@localhost ~]# ansible group1 -m file -a "path=/tmp/112 state=absent"
192.168.17.106 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"path": "/tmp/112","state": "absent"
}
192.168.17.105 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"path": "/tmp/112","state": "absent"
}

absent:没有、缺席、缺乏的意思。

删除目录:

[root@localhost ~]# ansible group1 -m file -a "path=/test state=absent"
192.168.17.105 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"path": "/test","state": "absent"
}
192.168.17.106 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"path": "/test","state": "absent"
}

absent:目录将会递归被删除。文件和软链接将会unlinked。

创建软链接:

[root@localhost ~]# ansible group1 -m file -a "src=/tmp/111 path=/tmp/222 state=link"
192.168.17.105 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"dest": "/tmp/222","gid": 0,"group": "root","mode": "0777","owner": "root","size": 8,"src": "/tmp/111","state": "link","uid": 0
}
192.168.17.106 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"dest": "/tmp/222","gid": 0,"group": "root","mode": "0777","owner": "root","size": 8,"src": "/tmp/111","state": "link","uid": 0
}

我们看到软链接的文件的大小稍微大点。

硬链接:hard

[root@localhost ~]# ansible group1 -m file -a "src=/tmp/111 path=/tmp/555 state=hard"
192.168.17.105 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"dest": "/tmp/555","gid": 2,"group": "daemon","mode": "0777","owner": "ftp","size": 0,"src": "/tmp/111","state": "hard","uid": 14
}
192.168.17.106 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"dest": "/tmp/555","gid": 2,"group": "daemon","mode": "0777","owner": "ftp","size": 0,"src": "/tmp/111","state": "hard","uid": 14
}

硬链接是看inode号。

group的组配置,要注意下是要存在的。

修改硬链接的属性:file ,如果是硬链接,就需要添加state=file,这个要注意的。

[root@localhost ~]# ansible group1 -m file -a "path=/tmp/555 state=file owner=ftp group=daemon mode=000"
192.168.17.105 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"gid": 2,"group": "daemon","mode": "0000","owner": "ftp","path": "/tmp/555","size": 0,"state": "hard","uid": 14
}
192.168.17.106 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"gid": 2,"group": "daemon","mode": "0000","owner": "ftp","path": "/tmp/555","size": 0,"state": "hard","uid": 14
}

修改文件的拥有者和属组:

[root@localhost ~]# ansible group1 -m file -a "path=/tmp/aaa owner=ftp group=daemon mode=000"
192.168.17.105 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"gid": 2,"group": "daemon","mode": "0000","owner": "ftp","path": "/tmp/aaa","size": 0,"state": "file","uid": 14
}
192.168.17.106 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"gid": 2,"group": "daemon","mode": "0000","owner": "ftp","path": "/tmp/aaa","size": 0,"state": "file","uid": 14
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/94906.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

API管理风险:如何确保您的API安全与可靠?

API管理风险:如何确保您的API安全与可靠? 随着数字化时代的到来,应用程序接口(API)在现代软件开发中发挥着关键的作用。然而,API管理过程中存在着各种潜在的风险。本文将探讨如何有效地管理和缓解这些风险…

linux安装firefox

1.下载对应包 https://www.mozilla.org/en-US/firefox/all/#product-desktop-release 2. 挂载桌面链接(如果/usr/bin/firefox下有的话,先删除) ln -s /opt/firefox/firefox /usr/bin/firefox 3.执行以下命令,即可启动Firefox客户端: firefox

easyexcel poi根据模板导出Excel

1.导入依赖 <!-- poi依赖--> <dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>4.0.1</version> </dependency> <!-- poi对于excel 2007的支持依赖--> <dependency…

大数据项目实战(Sqoop安装)

一&#xff0c;搭建大数据集群环境 1.4 Sqoop安装 1.sqoop安装 &#xff08;1&#xff09;上传安装包 &#xff08;2&#xff09;解压安装包 tar -zxvf sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz -C /export/servers &#xff08;3&#xff09;重命名 mv sqoop-1.4.6.b…

安装kali虚拟机镜像的坑

1.0 安装虚拟机镜像成功之后&#xff0c;只有光标&#xff0c;没有界面 在VMware上安装kali linux环境时&#xff0c;根据提示操作完成后&#xff0c;开启虚拟机&#xff0c;屏幕黑屏&#xff0c;左上角有一个光标在闪&#xff0c;一直开不了机。 出现问题的原因&#xff0c;…

拓世科技集团 | “书剑人生”李步云学术思想研讨会暨李步云先生九十华诞志庆

2023年&#xff0c;中国改革开放迎来了45周年&#xff0c;改革春风浩荡&#xff0c;席卷神州大地&#xff0c;45年间&#xff0c;中国特色社会主义伟大事业大步迈入崭新境界&#xff0c;一路上结出了饶为丰硕的果实。中华民族在这45年间的砥砺前行&#xff0c;不仅使中国的经济…

ELK安装、部署、调试 (二) ES的安装部署

ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎&#xff0c;基于RESTful web接口操作ES&#xff0c;也可以利用Java API。Elasticsearch是用Java开发的&#xff0c;并作为Apache许可条款下的开放源码发布&#xff0c;是当前流行的企业…

漂浮岛场景WebGL效果解析

访问在线地址&#xff0c;代码在此处。 场景构图 该场景使用了3个岩石模型&#xff0c;一些通用的阙类植物、树木模型&#xff0c;还有空中的鸟类模型。 场景的渲染顺序&#xff1a;深度预通道&#xff0c;岩石&#xff0c;鸟类&#xff0c;天空&#xff0c;云粒子。 相机…

yolov5模型转换

yolov5本身release目录有提供了onnx转换好的模型&#xff0c;想着也自己操作一遍&#xff0c;可是实际操作却遇到了问题&#xff0c;这里做下记录方便后续可能用到 安装onnx&#xff0c;转的时候提示出错ONNX: export failure 0.1s: Unsupported ONNX opset version: 17 修改…

Android 13 - Media框架(9)- NuPlayer::Decoder

这一节我们将了解 NuPlayer::Decoder&#xff0c;学习如何将 MediaCodec wrap 成一个强大的 Decoder。这一节会提前讲到 MediaCodec 相关的内容&#xff0c;如果看不大懂可以先跳过此篇。原先觉得 Decoder 部分简单&#xff0c;越读越发现自己的无知&#xff0c;Android 源码真…

Linux 多进程解决客户端与服务器端通信

写一个服务器端用多进程处理并发&#xff0c;使两个以上的客户端可以同时连接服务器端得到响应。每当接受一个新的连接就fork产生一个子进程&#xff0c;让子进程去处理这个连接&#xff0c;父进程只用来接受连接。 与多线程相比的不同点&#xff1a;多线程如果其中一个线程操…

中科驭数以DPU先进计算技术,夯实下一代金融IT基础设施底座

由中国计算机学会主办的第19届CCF全国高性能计算学术年会&#xff08;CCF HPC China 2023&#xff09;于8月23日至26日在青岛成功召开。在“高性能金融计算”主题论坛上&#xff0c;中科驭数高级副总裁、CTO卢文岩应邀发表了题为《DPU先进计算技术助力下一代交易底座》的演讲&a…