当前位置:网站首页>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


边栏推荐
猜你喜欢

JeeSite New Report

UE4 opens doors with overlapping events

请写出SparkSQL语句

What is the function of industrial-grade remote wireless transmission device?

UE4 opens door via interaction (keyboard key)

About the installation of sklearn library

事件解析树Drain3使用方法和解释

UI自动化测试 App的WebView页面中,当搜索栏无搜索按钮时处理方法

Acid (ACID) Base (BASE) Principles for Database Design

Detailed explanation of Mysql's undo log
随机推荐
UE4 为子弹蓝图添加声音和粒子效果
UE4 通过互动(键盘按键)开门
dedecms织梦tag标签不支持大写字母修复
mutillidae下载及安装
Haproxy搭建Web群集
UE4 在游戏运行时更改变量 (通过鼠标滑轮来更改第一人称角色的最大行走速度)
UE4 通过与其它Actor互动开门
The production method of the powered small sailboat is simple, the production method of the electric small sailboat
Is the NPDP certificate high in gold content?Compared to PMP?
多列属性column元素的可见性:display、visibility、opacity、垂直对齐方式:vertical-align、z-index 越大越显示在上层
[MRCTF2020] Ezpop (detailed)
overloaded operator
概率论的学习和整理8: 几何分布和超几何分布
[Geek Challenge 2019]FinalSQL
BI业务分析思维:现金流量风控分析(二)信用、流动和投资风险
About the installation of sklearn library
AUTOCAD——标注关联
UE4 通过重叠事件开启门
[BJDCTF2020]EasySearch
狗仔队:表面编辑多视点图像处理