当前位置:网站首页>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
边栏推荐
- The log causes these pits in the thread block, you have to guard against
- [CISCN2019 South China Division]Web11
- Detailed explanation of Mysql's undo log
- C语言-大白话理解原码,反码和补码
- overloaded operator
- The first performance test practice, there are "100 million" a little nervous
- write the story about us
- 35岁的软件测试工程师,月薪不足2W,辞职又怕找不到工作,该何去何从?
- [informix] Resolving startup errors and solutions
- 36-Jenkins-Job迁移
猜你喜欢
Mysql的undo log详解
UE4 通过重叠事件开启门
UE4 更改组件变量 (以修改第一人称角色模板的最大行走速度和跳跃高度为例)
[8.1] Code Source - [The Second Largest Number Sum] [Stone Game III] [Balanced Binary Tree]
Acid (ACID) Base (BASE) Principles for Database Design
[BJDCTF2020] EasySearch
8.04 Day35-----MVC three-tier architecture
How to solve complex distribution and ledger problems?
虚证、实证如何鉴别?
dedecms后台生成提示读取频道信息失败的解决方法
随机推荐
BI业务分析思维:现金流量风控分析(二)信用、流动和投资风险
1007 Climb Stairs (greedy | C thinking)
四位数显表头设计
作业8.4 进程间的通信 管道与信号
Cron(Crontab)--使用/教程/实例
Day14 jenkins部署
虚证、实证如何鉴别?
AUTOCAD - dimension association
write the story about us
bytebuffer use demo
MySql index learning and use; (I think it is detailed enough)
creo怎么测量点到面的距离
[SWPU2019]Web1
银行数据采集,数据补录与指标管理3大问题如何解决?
Cron(Crontab)--use/tutorial/example
Index Mysql in order to optimize paper 02 】 【 10 kinds of circumstances and the principle of failure
[Surveying] Quick Summary - Excerpt from Gaoshu Gang
The most comprehensive exam questions for software testing engineers in 2022
为什么刚考完PMP,就开始准备软考了?
UE4 为子弹蓝图添加声音和粒子效果