[root@master ansible]# ansible-playbook --help
--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 #测试运行
-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 #设置额外的变量为key=value或YAML/JSON,如果文件名后缀为@
set additional variables as key=value or YAML/JSON, if
filename prepend with @
--flush-cache clear the fact cache for every host in inventory #清除清单中所有主机的事实缓存
--force-handlers run handlers even if a task fails #即使任务失败也要运行处理程序
-f FORKS, --forks=FORKS
specify number of parallel processes to use
(default=5) #指定要使用的并行进程数
(默认= 5)
-h, --help show this help message and exit #查看帮助
-i INVENTORY, --inventory=INVENTORY, --inventory-file=INVENTORY
specify inventory host path or comma separated host
list. --inventory-file is deprecated #指定目录主机路径或逗号分隔的主机列表。——inventory-file弃用
-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-tags list all available tags #列出所有可用标签
--list-tasks list all tasks that would be executed #列出所有要执行的任务
-M MODULE_PATH, --module-path=MODULE_PATH
prepend colon-separated path(s) to module library (def
ault=~/.ansible/plugins/modules:/usr/share/ansible/plu
gins/modules)
--skip-tags=SKIP_TAGS
only run plays and tasks whose tags do not match these
values #只运行标签不匹配的play和task值
--start-at-task=START_AT_TASK
start the playbook at the task matching this name #试运行剧本
--step one-step-at-a-time: confirm each task before running #一次一步:运行前确认每个任务
--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 只运行带有这些值的任务#
--vault-id=VAULT_IDS the vault identity to use #要使用的保险库身份
--vault-password-file=VAULT_PASSWORD_FILES
vault password file #库密码文件
-v, --verbose verbose mode (-vvv for more, -vvvv to enable
connection debugging) #详细模式
--version show program's version number, config file location,
configured module search path, module location,
executable location and exit
常用选项:
1、语法检测
[root@master ansible]# ansible-playbook install_nginx.yml --syntax-check
playbook: install_nginx.yml
2、查看所有任务列表
[root@master ansible]# ansible-playbook install_nginx.yml --list-task
playbook: install_nginx.yml
play #1 (all): all TAGS: []
tasks:
1. Install nginx TAGS: []
2. Copy index.html TAGS: []
3. Start nginx TAGS: []
3、查看所有针对的目标主机
[root@master ansible]# ansible-playbook install_nginx.yml --list-hosts
playbook: install_nginx.yml
play #1 (all): all TAGS: []
pattern: ['all']
hosts (3):
node1
master
node2
4、测试运行 --check / -C
[root@master ansible]# ansible-playbook install_nginx.yml --check
PLAY [all] **********************************************************************************
TASK [Gathering Facts] **********************************************************************
ok: [node2]
ok: [node1]
ok: [master]
5、限制执行范围 --limit -l
[root@master ansible]# ansible-playbook install_nginx.yml --limit node1
PLAY [all] **********************************************************************************
TASK [Gathering Facts] **********************************************************************
ok: [node1]
6、运行指定的任务 --start-at-task='name'
[root@master ansible]# ansible-playbook install_nginx.yml --start-at-task='1. Install nginx'
PLAY [all] **********************************************************************************
TASK [Gathering Facts] **********************************************************************
ok: [node1]
ok: [master]
ok: [node2]
7、正式运行
[root@master ansible]# ansible-playbook install_nginx.yml
PLAY [all] **********************************************************************************
TASK [Gathering Facts] **********************************************************************
ok: [node2]
ok: [master]
ok: [node1]