ansible 手册

Usage: ansible [options]

Options:
对应模块的命令和参数
-a MODULE_ARGS, --args=MODULE_ARGS

                    module arguments
在运行的时候要求输入密码

--ask-vault-pass ask for vault password

用异步的方式运行,设置失败时间x秒

-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
用于当更改(小)文件和模板时(如copy fetch),显示这些文件的差异;跟 --check参数一起使用很有效。

-D, --diff when changing (small) files and templates, show the

                    differences in those files; works great with --check
用于给变量赋值,比如ansible -i c all -m shell -s -e "name=haha" -a "echo {{ name }}"

-e EXTRA_VARS, --extra-vars=EXTRA_VARS

                    set additional variables as key=value or YAML/JSON

指定要使用的并行进程数,默认是5个进程数,主要首先于系统资源啦

-f FORKS, --forks=FORKS

                    specify number of parallel processes to use
                    (default=5)

查看help信息,显示完后进程会退出

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

指定描述主机集合的文件,或者是用逗号隔开的主机列表
不指定的话,默认是读取/etc/ansible/hosts
比如ansible -i host all -m shell -s -a "uptime" 和 ansible -i 172.17.16.4,172.17.16.5 all -m shell -s -a "uptime"

-i INVENTORY, --inventory-file=INVENTORY

                    specify inventory host path
                    (default=/etc/ansible/hosts) or comma separated host
                    list.
字面意思是 进一步将所选主机限制为其他模式 ,但个人不理解

-l SUBSET, --limit=SUBSET

                    further limit selected hosts to an additional pattern

输出的 结果只会是主机集合的相关信息,不会执行其他的指令,比如ansible -i host all --list-hosts

--list-hosts outputs a list of matching hosts; does not execute

                    anything else
指定要执行的模块名称,比如shell command等

-m MODULE_NAME, --module-name=MODULE_NAME

                    module name to execute (default=command)

指定模块库的路径,默认为空

-M MODULE_PATH, --module-path=MODULE_PATH

                    specify path(s) to module library (default=None)

指定新的ssh密码文件或者key

--new-vault-password-file=NEW_VAULT_PASSWORD_FILE

                    new vault password file for rekey

-o参数会导致stdout显示在同一行

-o, --one-line condense output

--output=OUTPUT_FILE output file name for encrypt or decrypt; use - for

                    stdout

-p参数,在使用使用-B参数的情况下,用-p参数来设置轮询间隔,默认是15s
-P POLL_INTERVAL, --poll=POLL_INTERVAL

                    set the poll interval if using -B (default=15)

对playbook进行语法检查,但不会真正执行它
--syntax-check perform a syntax check on the playbook, but do not

                    execute it

将输出的日志输出到指定的目录,日志文件名会以主机名命名
-t TREE, --tree=TREE log output to this directory

指定文件库密码文件,参考"http://chuansong.me/n/392345151240"
--vault-password-file=VAULT_PASSWORD_FILE

                    vault password file

详情模式,可以在执行中打印详情
-v, --verbose verbose mode (-vvv for more, -vvvv to enable

                    connection debugging)

查看ansible版本号
--version show program's version number and exit

建连的一些参数
Connection Options:

control as whom and how to connect to hosts
使用ssh密码
-k, --ask-pass      ask for connection password
指定ssh key文件
--private-key=PRIVATE_KEY_FILE, --key-file=PRIVATE_KEY_FILE
                    use this file to authenticate the connection
指定ssh登陆的用户
-u REMOTE_USER, --user=REMOTE_USER
                    connect as this user (default=None)

连接类型,可以是local,ssh或者paramiko,默认是smart,让ansible自己选
-c CONNECTION, --connection=CONNECTION
                    connection type to use (default=smart)
设置连接超时时间
-T TIMEOUT, --timeout=TIMEOUT
                    override the connection timeout in seconds
                    (default=10)
该设置将总是为sftp,scp,ssh附加到命令行,可用于为某个主机或组配置ProxyCommand
--ssh-common-args=SSH_COMMON_ARGS
                    specify common arguments to pass to sftp/scp/ssh (e.g.
                    ProxyCommand)
该设置将sftp附加到命令行
--sftp-extra-args=SFTP_EXTRA_ARGS
                    specify extra arguments to pass to sftp only (e.g. -f,
                    -l)
该设置将scp附加到命令行
--scp-extra-args=SCP_EXTRA_ARGS
                    specify extra arguments to pass to scp only (e.g. -l)
该设置将ssh附件到命令行
--ssh-extra-args=SSH_EXTRA_ARGS
                    specify extra arguments to pass to ssh only (e.g. -R)

Privilege Escalation Options:

control how and which user you become as on target hosts

切换到用sudo运行指令
-s, --sudo          run operations with sudo (nopasswd) (deprecated, use
                    become)

-U SUDO_USER, --sudo-user=SUDO_USER
                    desired sudo user (default=root) (deprecated, use
                    become)
用su运行操作(弃用, 使用become)
-S, --su            run operations with su (deprecated, use become)
-R SU_USER, --su-user=SU_USER
                    run operations with su as this user (default=root)
                    (deprecated, use become)
-b, --become        run operations with become (does not imply password
                    prompting)
--become-method=BECOME_METHOD
                    privilege escalation method to use (default=sudo),
                    valid choices: [ sudo | su | pbrun | pfexec | runas |
                    doas | dzdo ]
--become-user=BECOME_USER
                    run operations as this user (default=root)
--ask-sudo-pass     ask for sudo password (deprecated, use become)
--ask-su-pass       ask for su password (deprecated, use become)
-K, --ask-become-pass
                    ask for privilege escalation password

发表新评论