1. 程式人生 > >Ansible命令(3)

Ansible命令(3)

edit 啟動 擴展 幫助 dom log per at-t password

0.ansible

命令參數詳解:

[[email protected] ~]# ansible
Usage: ansible <host-pattern> [options]

Options:
-a MODULE_ARGS, --args=MODULE_ARGS 模塊的參數,如果執行默認COMMAND的模塊,即是命令參數,如:“date”,"pwd"等等
module arguments 模塊參數
-k, --ask-pass ask for SSH password 登錄密碼,提示輸入SSH密碼而不是假設基於密鑰的驗證


--ask-su-pass ask for su password su切換密碼
-K, --ask-sudo-pass ask for sudo password 提示密碼使用sudo,sudo表示提權操作
--ask-vault-pass ask for vault password
-B SECONDS, --background=SECONDS 後臺運行超時時間
run asynchronously, failing after X seconds
(default=N/A)

-C, --check don‘t make any changes; instead, try to predict some 只是測試一下會改變什麽內容,不會真正去執行;相反,試圖預測一些可能發生的變化
of the changes that may occur
-c CONNECTION, --connection=CONNECTION 連接類型使用。可能的選項是paramiko(SSH),SSH和地方。當地主要是用於crontab或啟動。
connection type to use (default=smart)

-f FORKS, --forks=FORKS 並行任務數。NUM被指定為一個整數,默認是5
specify number of parallel processes to use
(default=5)
-h, --help show this help message and exit 打開幫助文檔API
-i INVENTORY, --inventory-file=INVENTORY 指定庫存主機文件的路徑,默認為/etc/ansible/hosts
specify inventory host file
(default=/etc/ansible/hosts)
-l SUBSET, --limit=SUBSET 進一步限制所選主機/組模式 --limit=192.168.91.135 只對這個ip執行
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 執行模塊的名字,默認使用 command 模塊,所以如果是只執行單一命令可以不用 -m參數
module name to execute (default=command)
-M MODULE_PATH, --module-path=MODULE_PATH 要執行的模塊的路徑,默認為/usr/share/ansible/
specify path(s) to module library
(default=/usr/share/ansible/)
-o, --one-line condense output 壓縮輸出,摘要輸出.嘗試一切都在一行上輸出。
-P POLL_INTERVAL, --poll=POLL_INTERVAL 調查背景工作每隔數秒。需要- b
set the poll interval if using -B (default=15)
--private-key=PRIVATE_KEY_FILE 私鑰路徑,使用這個文件來驗證連接
use this file to authenticate the connection
-S, --su run operations with su 用 su 命令
-R SU_USER, --su-user=SU_USER 指定SU的用戶,默認是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到哪個用戶,默認為 root
desired sudo user (default=root)
-T TIMEOUT, --timeout=TIMEOUT 指定SSH默認超時時間, 默認是10S
override the SSH timeout in seconds (default=10)
-t TREE, --tree=TREE log output to this directory 將日誌內容保存在該輸出目錄,結果保存在一個文件中在每臺主機上。
-u REMOTE_USER, --user=REMOTE_USER 遠程用戶, 默認是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 詳細信息
connection debugging)
--version show program‘s version number and exit 輸出ansible的版本

特殊說明:

1. ansible是指令核心部分,其主要用於執行ad-hoc(點對點)命令,即單條命令。默認後面需要跟主機和選項部分,默認不指定模塊時,使用的是command模塊。

2. 默認使用的模塊是可以在ansible.cfg 中進行修改的。 /etc/ansible/ansible.cfg

舉例:

[[email protected] ~]# ansible 192.168.91.137 -a ‘pwd‘

192.168.91.137 | success | rc=0 >>

/root

1.ansible-doc

參數詳解:

[[email protected] ~]# ansible-doc -h
Usage: ansible-doc [options] [module...]

Show Ansible module documentation 顯示Ansible模塊文檔

Options:
--version show program‘s version number and exit 顯示ansible-doc的版本號
-h, --help show this help message and exit 顯示命令參數API文檔
-M MODULE_PATH, --module-path=MODULE_PATH 查詢模塊,--module-path=MODULE_PATH 指定模塊的路徑
Ansible modules/ directory
-l, --list List available modules 顯示已存在的所有模塊列表
-s, --snippet Show playbook snippet for specified module(s) 顯示playbook制定模塊的用法
-v Show version number and exit 顯示ansible-doc的版本號

舉例:

$ ansible-doc -l

$ ansible-doc -s command

2.ansible-galaxy

參數詳解:

[[email protected] ~]# ansible-galaxy -h
Usage: ansible-galaxy [init|info|install|list|remove] [--help] [options] ...

Options:
-h, --help show this help message and exit

See ‘ansible-galaxy <command> --help‘ for more information on a specific command.

  特殊說明:

ansible-galaxy 指令用於方便的從https://galaxy.ansible.com/ 站點下載第三方擴展模塊,我們可以形象的理解其類似於centos下的yum、python下的pip或easy_install

舉例:

[[email protected] ~]# ansible-galaxy install aeriscloud.docker

- downloading role ‘docker‘, owned by aeriscloud

- downloading role from https://github.com/AerisCloud/ansible-docker/archive/v1.0.0.tar.gz

- extracting aeriscloud.docker to /etc/ansible/roles/aeriscloud.docker

- aeriscloud.docker was installed successfully

3.ansible-playbook

參數詳解:

[[email protected] ~]# ansible-playbook -h
Usage: ansible-playbook playbook.yml

Options:
-k, --ask-pass ask for SSH password
--ask-su-pass ask for su password
-K, --ask-sudo-pass ask for sudo password
--ask-vault-pass ask for vault password
-C, --check don‘t make any changes; instead, try to predict some
of the changes that may occur
-c CONNECTION, --connection=CONNECTION
connection type to use (default=smart)
-D, --diff when changing (small) files and templates, show the
differences in those files; works great with --check
-e EXTRA_VARS, --extra-vars=EXTRA_VARS
set additional variables as key=value or YAML/JSON
--force-handlers run handlers even if a task fails
-f FORKS, --forks=FORKS
specify number of parallel processes to use
(default=5)
-h, --help show this help message and exit
-i INVENTORY, --inventory-file=INVENTORY
specify inventory host file
(default=/etc/ansible/hosts)
-l SUBSET, --limit=SUBSET
further limit selected hosts to an additional pattern
--list-hosts outputs a list of matching hosts; does not execute
anything else
--list-tasks list all tasks that would be executed
-M MODULE_PATH, --module-path=MODULE_PATH
specify path(s) to module library
(default=/usr/share/ansible/)
--private-key=PRIVATE_KEY_FILE
use this file to authenticate the connection
--skip-tags=SKIP_TAGS
only run plays and tasks whose tags do not match these
values
--start-at-task=START_AT
start the playbook at the task matching this name
--step one-step-at-a-time: confirm each task before running
-S, --su run operations with su
-R SU_USER, --su-user=SU_USER
run operations with su as this user (default=root)
-s, --sudo run operations with sudo (nopasswd)
-U SUDO_USER, --sudo-user=SUDO_USER
desired sudo user (default=root)
--syntax-check perform a syntax check on the playbook, but do not
execute it
-t TAGS, --tags=TAGS only run plays and tasks tagged with these values
-T TIMEOUT, --timeout=TIMEOUT
override the SSH timeout in seconds (default=10)
-u REMOTE_USER, --user=REMOTE_USER
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
connection debugging)
--version show program‘s version number and exit

4.ansible-pull

參數詳解:

[[email protected] ~]# ansible-pull -h
Usage: ansible-pull [options] [playbook.yml]

Options:
-K, --ask-sudo-pass ask for sudo password
-C CHECKOUT, --checkout=CHECKOUT
branch/tag/commit to checkout. Defaults to behavior
of repository module.
-d DEST, --directory=DEST
directory to checkout repository to
-e EXTRA_VARS, --extra-vars=EXTRA_VARS
set additional variables as key=value or YAML/JSON
-f, --force run the playbook even if the repository could not be
updated
-h, --help show this help message and exit
-i INVENTORY, --inventory-file=INVENTORY 指定庫存主機文件的路徑,默認為/etc/ansible/hosts
location of the inventory host file
-m MODULE_NAME, --module-name=MODULE_NAME 從倉庫檢查的模塊名,默認是git
Module name used to check out repository. Default is
git.
-o, --only-if-changed
only run the playbook if the repository has been
updated
--purge purge checkout after playbook run
-s SLEEP, --sleep=SLEEP
sleep for random interval (between 0 and n number of
seconds) before starting. this is a useful way to
disperse git requests
-U URL, --url=URL URL of the playbook repository
--vault-password-file=VAULT_PASSWORD_FILE
vault password file
-v, --verbose Pass -vvvv to ansible-playbook

5.ansible-vault

參數詳解:

[[email protected] ~]# ansible-vault
Usage: ansible-vault [create|decrypt|edit|encrypt|rekey] [--help] [options] file_name

Options:
-h, --help show this help message and exit

See ‘ansible-vault <command> --help‘ for more information on a specific command.

特殊說明:

ansible-vault主要應用於配置文件中含有敏感信息,又不希望他能被人看到,vault可以幫你加密/解密這個配置文件,屬高級用法。主要對於playbooks裏比如涉及到配置密碼或其他變量時,可以通過該指令加密,這樣我們通過cat看到的會是一個密碼串類的文件,編輯的時候需要輸入事先設定的密碼才能打開。這種playbook文件在執行時,需要加上 –ask-vault-pass參數,同樣需要輸入密碼後才能正常執行。具體該部分可以參查官方博客。

Ansible命令(3)