ansible模块--command模块

网友投稿 810 2022-10-10

ansible模块--command模块

ansible模块--command模块

1.在远程主机上执行指定得命令 如:cat ls ,不能使用特殊得符号 :| > >>

[root@ansible ansible]# ansible -i hosts mysql -m command -a "hostname"192.168.56.88 | CHANGED | rc=0 >>mysql8[root@ansible ansible]# ansible -i hosts mysql -m command -a "ip a"192.168.56.88 | CHANGED | rc=0 >>1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: enp0s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:dd:a6:08 brd ff:ff:ff:ff:ff:ff inet 192.168.56.88/24 brd 192.168.56.255 scope global noprefixroute enp0s3 valid_lft forever preferred_lft forever inet6 fe80::6ac2:72f:9232:585b/64 scope link noprefixroute valid_lft forever preferred_lft forever[root@ansible ansible]# ansible -i hosts mysql -m command -a "ls -l"192.168.56.88 | CHANGED | rc=0 >>total 4-rw-------. 1 root root 1715 Sep 12 14:36 anaconda-ks.cfg

2.如果使用ansible不支持的特殊字符,则抛错​

[root@ansible ansible]# ansible -i hosts mysql -m command -a "ls -l | grep an"192.168.56.88 | FAILED | rc=2 >>ls: cannot access |: No such file or directoryls: cannot access grep: No such file or directoryls: cannot access an: No such file or directorynon-zero return code

3.creates和removescreates:当指定文件存在时,后一条命令不执行 / 指定文件不存在,后一条命令执行removes:当指定文件存在时,后一条命令执行 / 指定文件不存在,后一条命令不执行

# /etc/fstab文件存在,则cat命令不执行[root@ansible ansible]# ansible -i hosts mysql -m command -a "creates=/etc/fstab cat /etc/fstab"192.168.56.88 | SUCCESS | rc=0 >>skipped, since /etc/fstab exists# /etc/fstab文件存在,则cat命令执行[root@ansible ansible]# ansible -i hosts mysql -m command -a "removes=/etc/fstab cat /etc/fstab"192.168.56.88 | CHANGED | rc=0 >>## /etc/fstab# Created by anaconda on Sun Sep 12 14:30:00 2021## Accessible filesystems, by reference, are maintained under '/dev/disk'# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info#/dev/mapper/rhel-root / xfs defaults 0 0UUID=747ccae3-a4b8-4b11-b77f-cd3d704f0e57 /boot xfs defaults 0 0/dev/mapper/rhel-swap swap swap defaults 0 0

ansible

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Talika- 用户进行程序切换的小软件(她离开了的英文)
下一篇:微信小程序跳转层数检测工具
相关文章

 发表评论

暂时没有评论,来抢沙发吧~