warning: python-simplejson-2.0.9-8.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key> Preparing... ########################################### [100%]
1:python-simplejson ########################################### [100%] 5. ansible命令模块以及参数查询
(1) ansible命令语法
语法 ansible <host-pattern> [options]
ansible <pattern_goes_here> -m <module_name> -a <arguments>
选项:
-i 设备列表路径,可制定一些动态路径
-f 并行任务数
-private-key 私钥路径
-m 模块名 默认不指定模块就是采用command模块
-M 模块夹在路径
-a 参数
-k 登陆密码
-K sudo密码
-t 输出结果保存路径
-B 后台运行超时时间
-P 调查后台程序时间
-u 执行用户
-U sudo用户
-l 限制设备范围
-s 是此用户sudo无需输入密码
(2) 查看ansible的模块以及参数
# ansible-doc
-l 列出所有的ansible模块
-s 列出该模块的相关指令
[root@master ~]# ansible-doc -l
boundary_meter Manage boundary meters
bzr Deploy software (or files) from bzr branches
campfire Send a message to Campfire
capabilities Manage Linux capabilities
cloudformation create a AWS CloudFormation stack
command Executes a command on a remote node
composer Dependency Manager for PHP
copy Copies files to remote locations.
cpanm Manages Perl library dependencies.
cron Manage cron.d and crontab entries.
datadog_event Posts events to DataDog service
[root@master ~]# ansible-doc -s command
- name: E x e c u t e s a c o m m a n d o n a r e m o t e n o d e
action: command
chdir # cd into this directory before running the command
creates # a filename, when it already exists, this step will *not* be run.
executable # change the shell used to execute the command. Should be an absolute path to the executable.
free_form= # the command module takes a free form command to run. There is no parameter actually named 'free form'. See the
examples!
removes # a filename, when it does not exist, this step will *not* be run.
warn # if command warnings are on in ansible.cfg, do not warn about this particular line if set to no/false. 6. 通过密码方式进行验证,加入-k参数
#提供了三种方式:一个在hosts文件中加入密码,一种是免密钥方式,一种是采用-k方式手动输入密码,常用于临时测试。
[root@master ansible]# ansible all -m ping -k
SSH password:
192.168.10.192 | success >> {
"changed": false,
"ping": "pong"
}
192.168.10.191 | success >> {
"changed": false,
"ping": "pong"
} 7. 常用示例:
[root@master ansible]# ansible test -a 'df -h' #这个省略了-m command模块名,-a接参数,可以指行linux命令
#执行操作系统命令可以采用command,shell,raw等,其中shell可以使用管道以及命令带参,script通常用执行脚本等,具体可以查看相关参数。
192.168.0.125 | success | rc=0 >>