当前位置:网站首页>【无标题】
【无标题】
2022-08-04 23:20:00 【我是渣渣辉】
1.command,shell,raw,script模块的作用和区别
command、shell模块:
相同点:要求受管主机上安装Python。
不同点:command可以在受管主机上执行shell命令,但是不支持环境变量和操作符(例如 ‘|’, ‘<’, ‘>’, ‘&’)
shell模块调用的/bin/sh指令执行。
raw模块:
不需要受管主机上安装Python,直接使用远程shell运行命令,通常用于无法安装Python的系统(例如网络设备等)。
command 模块的使用: 去执行一个脚本文件command.sh, command.sh文件的功能是echo “I am command module”
[[email protected] ~]# ansible test -m command -a "bash command chdir=/root"
node2.example.com | CHANGED | rc=0 >>
I am command module
shell模块执行命令 ls /root | grep txt
[[email protected] ~]# ansible test -m shell -a "ls /root | grep txt"
node2.example.com | CHANGED | rc=0 >>
file.txt
raw模块执行pwd命令
[[email protected] ~]# ansible test -m shell -a "pwd"
node2.example.com | CHANGED | rc=0 >>
/home/student
script模块执行 script.sh文件,文件的内容为 echo “I am script module”
[[email protected] ~]# ansible test -m script -a "/root/script.sh"
node2.example.com | CHANGED => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to node2.example.com closed.\r\n",
"stderr_lines": [
"Shared connection to node2.example.com closed."
],
"stdout": "I am script module\r\n",
"stdout_lines": [
"I am script module"
]
}
2.file模块:
创建文件,并指定用户,用户组为student, 且权限为600
[[email protected] ~]# ansible test -m file -a "path=/root/file2 state=touch owner=student group=student mode=600 "
node2.example.com | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"dest": "/root/file2",
"gid": 1001,
"group": "student",
"mode": "0600",
"owner": "student",
"secontext": "unconfined_u:object_r:admin_home_t:s0",
"size": 0,
"state": "file",
"uid": 1001
}
创建目录,并指定用户,用户组为student, 且权限为755
[[email protected] ~]# ansible test -m file -a "path=/root/dir state=directory owner=student group=student mode=755 "
node2.example.com | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"gid": 1001,
"group": "student",
"mode": "0755",
"owner": "student",
"path": "/root/dir",
"secontext": "unconfined_u:object_r:admin_home_t:s0",
"size": 6,
"state": "directory",
"uid": 1001
}
创建链接文件
[[email protected] ~]# ansible test -m file -a "path=/root/file3 src=/root/file1 state=link"
node2.example.com | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"dest": "/root/file3",
"gid": 0,
"group": "root",
"mode": "0777",
"owner": "root",
"secontext": "unconfined_u:object_r:admin_home_t:s0",
"size": 11,
"src": "/root/file1",
"state": "link",
"uid": 0
}
删除第一个创建的文件
[[email protected] ~]# ansible test -m file -a "path=/root/file1 state=absent"
node2.example.com | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"path": "/root/file1",
"state": "absent"
}
3.copy
复制文件
[[email protected] ~]# ansible test -m copy -a "src=/root/file1 dest=/root/"
node2.example.com | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"dest": "/root/file1",
"gid": 0,
"group": "root",
"md5sum": "d41d8cd98f00b204e9800998ecf8427e",
"mode": "0644",
"owner": "root",
"secontext": "system_u:object_r:admin_home_t:s0",
"size": 0,
"src": "/home/student/.ansible/tmp/ansible-tmp-1659622665.9384096-11300-258171013076166/source",
"state": "file",
"uid": 0
}
复制目录
[[email protected] ~]# ansible test -m copy -a "src=/root/dir1 dest=/root/"
node2.example.com | SUCCESS => {
"changed": false,
"dest": "/root/",
"src": "/root/dir1"
}
4.fetch
从被控制主机上取文件
[[email protected] ~]# ansible test -m fetch -a "src=/root/file.txt dest=/root/ flat=yes"
node2.example.com | CHANGED => {
"changed": true,
"checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"dest": "/root/file.txt",
"md5sum": "d41d8cd98f00b204e9800998ecf8427e",
"remote_checksum": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
"remote_md5sum": null
}
5.synchronize
pull: 从被控制主机上拉取目录
[[email protected] ~]# ansible test -m synchronize -a "src=/root/file3 dest=/root/ mode=pull"
node2.example.com | CHANGED => {
"changed": true,
"cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh='/usr/bin/ssh -S none -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' --rsync-path='sudo -u root rsync' --out-format='<<CHANGED>>%i %n%L' [email protected]:/root/file3 /root/",
"msg": "cL+++++++++ file3 -> /root/file1\n",
"rc": 0,
"stdout_lines": [
"cL+++++++++ file3 -> /root/file1"
]
}
push:往被控制主机上推送目录
[[email protected] ~]# ansible test -m synchronize -a "src=/root/2 dest=/root/ mode=push"
node2.example.com | CHANGED => {
"changed": true,
"cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh='/usr/bin/ssh -S none -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' --rsync-path='sudo -u root rsync' --out-format='<<CHANGED>>%i %n%L' /root/2 [email protected]:/root/",
"msg": "<f+++++++++ 2\n",
"rc": 0,
"stdout_lines": [
"<f+++++++++ 2"
]
}
边栏推荐
- Qt中的常用控件
- 【字符串函数内功修炼】strlen + strstr + strtok + strerror(三)
- 【内存操作函数内功修炼】memcpy + memmove + memcmp + memset(四)
- 为何越来越多人选择进入软件测试行业?深度剖析软件测试的优势...
- Nuclei (2) Advanced - In-depth understanding of workflows, Matchers and Extractors
- The market value of 360 has evaporated by 390 billion in four years. Can government and enterprise security save lives?
- 【字符串函数内功修炼】strncpy + strncat + strncmp(二)
- kernel hung_task死锁检测机制原理实现
- 2022年华数杯数学建模
- 堪称奔驰“理财产品”,空间媲美宝马X5,采用了非常运动的外观
猜你喜欢

话题 | 雾计算和边缘计算有什么区别?

Shell编程之循环语句与函数的使用

uniapp横向选项卡(水平滚动导航栏)效果demo(整理)
![[Cultivation of internal skills of string functions] strncpy + strncat + strncmp (2)](/img/9f/9221c081cfa86caccbbd02916a6208.png)
[Cultivation of internal skills of string functions] strncpy + strncat + strncmp (2)

安全软件 Avast 与赛门铁克诺顿 NortonLifeLock 合并案获英国批准,市值暴涨 43%

一点点读懂cpufreq(一)

如何根据地址获取函数名

【字符串函数内功修炼】strlen + strstr + strtok + strerror(三)

Nuclei(二)进阶——深入理解workflows、Matchers和Extractors

Uniapp dynamic sliding navigation effect demo (finishing)
随机推荐
【无标题】
吐槽 | 参加IT培训的正确姿势
【游戏建模模型制作全流程】ZBrush蜥蜴模型雕刻教程
Service Mesh落地路径
npm基本操作及命令详解
The Go Programming Language (Introduction)
现在学习次世代3D游戏建模还能找到高薪好工作吗
【手撕AHB-APB Bridge】~ AMBA总线 之 AHB
@Async注解的作用以及如何实现异步监听机制
学生管理系统架构设计
一点点读懂cpufreq(二)
线性DP(下)
Shell编程之循环语句与函数的使用
[QNX Hypervisor 2.2用户手册]10.5 vdev ioapic
360市值四年蒸发3900亿,政企安全能救命吗?
Qt中的常用控件
kernel hung_task死锁检测机制原理实现
加解密在线工具和进制转化在线工具
中国的顶级黑客在国际上是一个什么样的水平?
招标公告 | 海纳百创公众号运维项目