Ansible 常用參數(shù)說明
使用ansible -h
命令就可以列出所有的命令參數(shù)箩溃,下面列舉了常用的一些參數(shù)瞭吃。
option | 說明 |
---|---|
-v |
輸出詳細(xì)信息 |
-i |
指定inventory文件,默認(rèn)使用/etc/ansible/hosts
|
-f |
fork的進(jìn)程個(gè)數(shù)涣旨,默認(rèn)為5 |
--list-hosts |
列出主機(jī)列表歪架,并不會(huì)執(zhí)行其他操作 |
-private-key=xxx |
指定ssh連接使用的文件 |
-m |
指定module,默認(rèn)為command
|
-a |
指定module的參數(shù) |
-o |
精簡(jiǎn)輸出內(nèi)容 |
-k |
提示輸入密碼 |
-K |
提示輸入sudo密碼霹陡,與-sudo 一起使用 |
-T |
設(shè)置連接超時(shí)時(shí)間 |
-B |
設(shè)置后臺(tái)運(yùn)行并設(shè)置超時(shí)時(shí)長(zhǎng) |
使用示例
-i示例
[root@centos7 ~]# cat hosts
[apache]
172.20.21.121
172.20.21.123
[nginx]
172.20.21.120
172.20.21.121
[servers:children]
apache
nginx
[servers:vars]
ansible_ssh_user='root'
ansible_ssh_pass='123456'
[root@centos7 ~]# ansible -i hosts apache --list-hosts
hosts (2):
172.20.21.121
172.20.21.123
[root@centos7 ~]# ansible -i hosts apache -m ping -o
172.20.21.123 | SUCCESS => {"changed": false, "ping": "pong"}
172.20.21.121 | SUCCESS => {"changed": false, "ping": "pong"}
-k示例
不指定module
和蚪,默認(rèn)將使用command
。
[root@centos7 ~]# ansible -i hosts apache -k -o -a "echo hello"
SSH password:
172.20.21.123 | SUCCESS | rc=0 | (stdout) hello
172.20.21.121 | SUCCESS | rc=0 | (stdout) hello
ansible-doc -s取得更詳細(xì)信息
希望知道更加詳細(xì)的module的信息烹棉,最好的方法是使用ansible自帶的ansible-doc
的-s
選項(xiàng)攒霹。
[root@centos7 ~]# ansible-doc -s raw
- name: Executes a low-down and dirty SSH command
raw:
executable: # change the shell used to execute the command. Should be an absolute path
to the executable. when using privilege
escalation (`become'), a default shell
will be assigned if one is not provided as
privilege escalation requires a shell.
free_form: # (required) the raw module takes a free form command to run. There is no
parameter actually named 'free form'; see
the examples!
[root@centos7 ~]# ansible-doc -s expect
- name: Executes a command and responds to prompts.
expect:
chdir: # Change into this directory before running the command.
command: # (required) The command module takes command to run.
creates: # A filename, when it already exists, this step will *not* be run.
echo: # Whether or not to echo out your response strings.
removes: # A filename, when it does not exist, this step will *not* be run.
responses: # (required) Mapping of expected string/regex and string to respond with.
If the response is a list, successive
matches return successive responses. List
functionality is new in 2.1.
timeout: # Amount of time in seconds to wait for the expected strings.
所有命令參數(shù)
[root@localhost ~]# ansible -h
Usage: ansible <host-pattern> [options]
Options:
-a MODULE_ARGS, --args=MODULE_ARGS 模塊的參數(shù),如果執(zhí)行默認(rèn)COMMAND的模塊,即是命令參數(shù),如:“date”,"pwd"等等
module arguments 模塊參數(shù)
-k, --ask-pass ask for SSH password 登錄密碼浆洗,提示輸入SSH密碼而不是假設(shè)基于密鑰的驗(yàn)證
--ask-su-pass ask for su password su切換密碼
-K, --ask-sudo-pass ask for sudo password 提示密碼使用sudo,sudo表示提權(quán)操作
--ask-vault-pass ask for vault password
-B SECONDS, --background=SECONDS 后臺(tái)運(yùn)行超時(shí)時(shí)間
run asynchronously, failing after X seconds
(default=N/A)
-C, --check don't make any changes; instead, try to predict some 只是測(cè)試一下會(huì)改變什么內(nèi)容催束,不會(huì)真正去執(zhí)行;相反,試圖預(yù)測(cè)一些可能發(fā)生的變化
of the changes that may occur
-c CONNECTION, --connection=CONNECTION 連接類型使用》纾可能的選項(xiàng)是paramiko(SSH),SSH和地方抠刺。當(dāng)?shù)刂饕怯糜赾rontab或啟動(dòng)。
connection type to use (default=smart)
-f FORKS, --forks=FORKS 并行任務(wù)數(shù)摘昌。NUM被指定為一個(gè)整數(shù),默認(rèn)是5
specify number of parallel processes to use
(default=5)
-h, --help show this help message and exit 打開幫助文檔API
-i INVENTORY, --inventory-file=INVENTORY 指定庫存主機(jī)文件的路徑,默認(rèn)為/etc/ansible/hosts
specify inventory host file
(default=/etc/ansible/hosts)
-l SUBSET, --limit=SUBSET 進(jìn)一步限制所選主機(jī)/組模式 --limit=192.168.91.135 只對(duì)這個(gè)ip執(zhí)行
further limit selected hosts to an additional pattern
--list-hosts outputs a list of matching hosts; does not execute
anything else
-m MODULE_NAME, --module-name=MODULE_NAME 執(zhí)行模塊的名字速妖,默認(rèn)使用 command 模塊,所以如果是只執(zhí)行單一命令可以不用 -m參數(shù)
module name to execute (default=command)
-M MODULE_PATH, --module-path=MODULE_PATH 要執(zhí)行的模塊的路徑聪黎,默認(rèn)為/usr/share/ansible/
specify path(s) to module library
(default=/usr/share/ansible/)
-o, --one-line condense output 壓縮輸出罕容,摘要輸出.嘗試一切都在一行上輸出。
-P POLL_INTERVAL, --poll=POLL_INTERVAL 調(diào)查背景工作每隔數(shù)秒稿饰。需要- b
set the poll interval if using -B (default=15)
--private-key=PRIVATE_KEY_FILE 私鑰路徑杀赢,使用這個(gè)文件來驗(yàn)證連接
use this file to authenticate the connection
-S, --su run operations with su 用 su 命令
-R SU_USER, --su-user=SU_USER 指定SU的用戶,默認(rèn)是root用戶
run operations with su as this user (default=root)
-s, --sudo run operations with sudo (nopasswd)
-U SUDO_USER, --sudo-user=SUDO_USER sudo到哪個(gè)用戶湘纵,默認(rèn)為 root
desired sudo user (default=root)
-T TIMEOUT, --timeout=TIMEOUT 指定SSH默認(rèn)超時(shí)時(shí)間, 默認(rèn)是10S
override the SSH timeout in seconds (default=10)
-t TREE, --tree=TREE log output to this directory 將日志內(nèi)容保存在該輸出目錄,結(jié)果保存在一個(gè)文件中在每臺(tái)主機(jī)上滤淳。
-u REMOTE_USER, --user=REMOTE_USER 遠(yuǎn)程用戶梧喷, 默認(rèn)是root用戶
connect as this user (default=root)
--vault-password-file=VAULT_PASSWORD_FILE
vault password file
-v, --verbose verbose mode (-vvv for more, -vvvv to enable 詳細(xì)信息
connection debugging)
--version show program's version number and exit 輸出ansible的版本
如果覺得有用,歡迎關(guān)注我的微信脖咐,有問題可以直接交流:
![你的關(guān)注是對(duì)我最大的鼓勵(lì)铺敌!](https://www.github.com/hoxis/token4md/raw/master/wechat-qcode.jpg)
你的關(guān)注是對(duì)我最大的鼓勵(lì)!