蔬菜小程序的开发全流程详解
810
2022-10-10
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:
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小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~