当目标主机的selinux没有关闭或者libselinux-python没有被安装的时候,还会出现以下提示:
"msg": "Aborting, target uses selinux but python bindings (libselinux-python) aren't installed!"
成功的返回如下:
192.168.7.17 | success >> {
"changed": true,
"dest": "/tmp/test/fstab",
"gid": 0,
"group": "root",
"md5sum": "aa75779b5e6ce91430e64e0a64ce15af",
"mode": "0700",
"owner": "root",
"secontext": "unconfined_u:object_r:admin_home_t:s0",
"size": 616,
"src": "/root/.ansible/tmp/ansible-tmp-1405058012.34-257276861833915/source",
"state": "file",
"uid": 0
}
There is also a module called command that will run any arbitrary command on the managed machine. This lets you configure it with any arbitrary command, such as a preprovided installer or a self-written script; it is also useful for rebooting machines. Please note that this module does not run the command within the shell, so you cannot perform redirection, use pipes, and expand shell variables or background commands. Ansible modules strive to prevent changes being made when they are not required. This is referred to as idempotency and can make running commands against multiple servers much faster. Unfortunately, Ansible cannot know if your command has changed anything or not, so to help it be more idempotent you have to give it some help. It can do this either via the creates or the removes argument. If you give a creates argument, the command will not be run if the filename argument exists. The opposite is true of the removes argument; if the filename exists, the command will be run. You run the command as follows: $ ansible machinename -m command -a 'rm -rf /tmp/testing removes=/tmp/testing' If there is no file or directory named /tmp/testing , the command output will indicate that it was skipped, as follows: machinename | skipped Otherwise, if the file did exist, it will look as follows: ansibletest | success | rc=0 >> Often it is better to use another module in place of the command module. Other modules offer more options and can better capture the problem domain they work in. For example, it would be much less work for Ansible and also the person writing the configurations to use the file module in this instance, since the file module will recursively delete something if the state is set to absent. So, this command would be equivalent to the following command: $ ansible machinename -m file -a 'path=/tmp/testing state=absent' If you need to use features usually available in a shell while running your command, you will need the shell module. This way you can use redirection, pipes, or job backgrounding. You can pick which shell to use with the executable argument. However, when you write the code, it also supports the creates argument but does not support the removes argument. You can use the shell module as follows: $ ansible machinename -m shell -a '/opt/fancyapp/bin/installer.sh > /var/log/fancyappinstall.log creates=/var/log/fancyappinstall.log'还有一个叫command的模块允许你在远程受管主机上运行任意命令,像一些安装命令、自己编写的脚本命令、甚至重启机器!但是,像一些不在shell里面运行的,比如执行了重定向、管道符、扩展的shell命令、以及后台命令无法执行!!
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/shouji/article-49614-8.html
粗粮还有真货吗