当前位置:网站首页>Detailed explanation of each module of ansible
Detailed explanation of each module of ansible
2022-08-05 04:20:00 【cy11114】
1.command,shell,raw,scriptThe role and difference of modules
1.1command shell raw区别
command、shell模块:
相同点:Requires installation on managed hostsPython.
不同点:commandCan be executed on a managed hostshell命令,But environment variables and operators are not supported(例如 '|', '<', '>', '&')
shell模块调用的/bin/sh指令执行.
raw模块:
No installation on managed hosts is requiredPython,use remote directlyshell运行命令,Usually used for not being able to installPython的系统(such as network equipment).
- command
- shell
- raw
You should try to avoid using these three modules to execute commands,Because other modules are mostly idempotent,Change tracking can be done automatically.command、shell、raw不具备幂等性.注: 幂等性:简单来讲,is the same input,输出相同,No matter how many times say,确认接口,If the order number is passed in,返回确认OK,If it has been confirmed,Call the confirmation interface again,Return if still confirmOK,Then this interface is idempotent.
2、command 模块的使用: to execute a script filecommand.sh, command.sh文件的功能是echo "I am command module"
[[email protected] ~]#vim command.sh
[[email protected] ~]# more ./.ansible/inventory
node1
[node]
node1
[node1:children]
node
test
[test]
node2
[[email protected] ~]# ansible node -m copy -a "src=/root/command.sh dest=/home/student"
[WARNING]: Found both group and host with same name: node1
node1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"checksum": "ce65dc39709980daa42a03e5d2ac1c97210446db",
"dest": "/home/student/command.sh",
"gid": 0,
"group": "root",
"md5sum": "5f4164eeeea65e4697bdb62d078065bb",
"mode": "0644",
"owner": "root",
"secontext": "unconfined_u:object_r:user_home_t:s0",
"size": 27,
"src": "/home/student/.ansible/tmp/ansible-tmp-1659481931.964826-27384-280168700260751/source",
"state": "file",
"uid": 0
}
[[email protected] ~]# ansible node -m command -a "ls -l /home/student/"
[WARNING]: Found both group and host with same name: node1
node1 | CHANGED | rc=0 >>
total 4
-rw-r--r--. 1 root root 27 Aug 2 12:33 command.sh
[[email protected] ~]# ansible node -m command -a "sh command.sh chdir=/home/student"
[WARNING]: Found both group and host with same name: node1
node1 | CHANGED | rc=0 >>
I am command module
3、shell模块执行命令 ls /root | grep txt

4、 raw模块执行pwd命令

5、script模块执行 script.sh文件,文件的内容为 echo "I am script module"
[[email protected] ~]# vim script.sh
[[email protected] ~]# pwd
/root
[[email protected] ~]# ansible node -m copy -a "src=/root/script.sh dest=/home/student"
[WARNING]: Found both group and host with same name: node1
node1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"checksum": "7fe9ae1b68ec686919b7799f9eef6c7eff006c8c",
"dest": "/home/student/script.sh",
"gid": 0,
"group": "root",
"md5sum": "ffb843f4c7a3cc3a444c21a7bdc2b2ac",
"mode": "0644",
"owner": "root",
"secontext": "unconfined_u:object_r:user_home_t:s0",
"size": 26,
"src": "/home/student/.ansible/tmp/ansible-tmp-1659482546.7581532-27525-45068860098080/source",
"state": "file",
"uid": 0
}
[[email protected] ~]# ansible node -m command -a "ls -l /home/student"
[WARNING]: Found both group and host with same name: node1
node1 | CHANGED | rc=0 >>
total 8
-rw-r--r--. 1 root root 27 Aug 2 12:33 command.sh
-rw-r--r--. 1 root root 26 Aug 2 12:43 script.sh
[[email protected] ~]# ansible node -m script -a "script.sh chdir=/home/student"
[WARNING]: Found both group and host with same name: node1
node1 | CHANGED => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to node1 closed.\r\n",
"stderr_lines": [
"Shared connection to node1 closed."
],
"stdout": "I am script module\r\n",
"stdout_lines": [
"I am script module"
]
6.file模块:
创建文件,并指定用户,用户组为student, 且权限为600
创建目录,并指定用户,用户组为student, 且权限为755
创建链接文件
Delete the first created file


7.copy
复制文件
复制目录

8.synchronize
pull: Pull the directory from the controlled host
push:Push the directory to the controlled host


边栏推荐
- Mysql的undo log详解
- UE4 opens doors with overlapping events
- [BSidesCF 2019] Kookie
- 4T硬盘剩余很多提示“No space left on device“磁盘空间不足
- The production method of the powered small sailboat is simple, the production method of the electric small sailboat
- Bosses, I noticed that a mysql CDC connector parameters scan. The incremental. Sna
- [SWPU2019]Web1
- JeeSite New Report
- Shell(4)条件控制语句
- 商业智能BI业务分析思维:现金流量风控分析(一)营运资金风险
猜你喜欢

请写出SparkSQL语句
![[CISCN2019 South China Division]Web11](/img/15/843334fec0a5cc8cfaba92aab938db.png)
[CISCN2019 South China Division]Web11

机器学习概述

使用IDEA连接TDengine服务器

Analyses the mainstream across technology solutions

The log causes these pits in the thread block, you have to guard against

write the story about us

bytebuffer internal structure

Paparazzi: Surface Editing by way of Multi-View Image Processing

特征预处理
随机推荐
How to solve the three major problems of bank data collection, data supplementary recording and index management?
dedecms后台生成提示读取频道信息失败的解决方法
第一次性能测试实践,有“亿”点点紧张
Ali's local life's single-quarter revenue is 10.6 billion, Da Wenyu's revenue is 7.2 billion, and Cainiao's revenue is 12.1 billion
The most comprehensive exam questions for software testing engineers in 2022
机器学习概述
【informix】解决启动报错大全,以及解决办法
Bosses, I noticed that a mysql CDC connector parameters scan. The incremental. Sna
No regrets, the appium automation environment is perfectly built
NPDP证书含金量高吗?跟PMP相比?
DEJA_VU3D - Cesium功能集 之 057-百度地图纠偏
Android interview question - how to write with his hands a non-blocking thread safe queue ConcurrentLinkedQueue?
App rapid development and construction experience: the importance of small programs + custom plug-ins
How to wrap markdown - md file
JeeSite新建报表
UE4 后期处理体积 (角色受到伤害场景颜色变淡案例)
[8.1] Code Source - [The Second Largest Number Sum] [Stone Game III] [Balanced Binary Tree]
Mini Program_Dynamic setting of tabBar theme skin
Redis1: Introduction to Redis, basic features of Redis, relational database, non-relational database, database development stage
4T硬盘剩余很多提示“No space left on device“磁盘空间不足