设为首页 收藏本站
查看: 1981|回复: 0

[经验分享] 3.3、Ansible命令参数详解

[复制链接]

尚未签到

发表于 2018-1-2 18:28:47 | 显示全部楼层 |阅读模式
  0.ansible
  命令参数详解:
[iyunv@localhost ~]# ansible

  Usage: ansible <host-pattern> [options]
  Options:
  -a MODULE_ARGS, --args=MODULE_ARGS    模块的参数,如果执行默认COMMAND的模块,即是命令参数,如:“date”,"pwd"等等
  modulearguments    模块参数
  -k, --ask-pass        ask forSSH password  登录密码,提示输入SSH密码而不是假设基于密钥的验证
  --ask-su-pass         ask forsu password    su切换密码
  -K, --ask-sudo-pass   ask forsudo password  提示密码使用sudo,sudo表示提权操作
  --ask-vault-pass      ask forvault password
  -B SECONDS, --background=SECONDS     后台运行超时时间
  run asynchronously,failing after X seconds
  (default=N/A)
  -C, --check           don't make anychanges; instead, try to predict some    只是测试一下会改变什么内容,不会真正去执行;相反,试图预测一些可能发生的变化
  of the changesthat may occur
  -c CONNECTION,--connection=CONNECTION   连接类型使用。可能的选项是paramiko(SSH),SSH和地方。当地主要是用于crontab或启动。
  connection typeto use (default=smart)
  -f FORKS, --forks=FORKS   并行任务数。NUM被指定为一个整数,默认是5
  specify number ofparallel processes to use
  (default=5)
  -h, --help            show thishelp message and exit   打开帮助文档API
  -i INVENTORY,--inventory-file=INVENTORY    指定库存主机文件的路径,默认为/etc/ansible/hosts
  specify inventoryhost file
  (default=/etc/ansible/hosts)
  -l SUBSET, --limit=SUBSET    进一步限制所选主机/组模式  --limit=192.168.91.135 只对这个ip执行
  further limitselected 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 toexecute (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 pollinterval if using-B (default=15)
  --private-key=PRIVATE_KEY_FILE    私钥路径,使用这个文件来验证连接
  use this file toauthenticate the connection
  -S, --su              run operations with su    用 su 命令
  -R SU_USER, --su-user=SU_USER      指定SU的用户,默认是root用户
  run operationswith 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 SSHtimeout in seconds (default=10)
  -t TREE, --tree=TREE  log output to thisdirectory     将日志内容保存在该输出目录,结果保存在一个文件中在每台主机上。
  -u REMOTE_USER, --user=REMOTE_USER    远程用户, 默认是root用户
  connect as thisuser (default=root)
  --vault-password-file=VAULT_PASSWORD_FILE
  vault passwordfile
  -v, --verbose         verbose mode (-vvv formore, -vvvv to enable    详细信息
  connectiondebugging)
  --version             show program'sversion number and exit   输出ansible的版本
  特殊说明:
  1. ansible是指令核心部分,其主要用于执行ad-hoc(点对点)命令,即单条命令。默认后面需要跟主机和选项部分,默认不指定模块时,使用的是command模块。
  2. 默认使用的模块是可以在ansible.cfg 中进行修改的。 /etc/ansible/ansible.cfg
  举例:
[iyunv@localhost ~]# ansible 192.168.91.137 -a 'pwd'

  192.168.91.137 | success | rc=0 >>
  /root
  1.ansible-doc
  参数详解:
[iyunv@localhost ~]#ansible-doc  -h

  Usage: ansible-doc [options] [module...]
  Show Ansible moduledocumentation     显示Ansible模块文档
  Options:
  --version             show program'sversion number and exit    显示ansible-doc的版本号
  -h, --help            show thishelp 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 forspecified module(s)   显示playbook制定模块的用法
  -v                    Show version number andexit   显示ansible-doc的版本号
  举例:
  $     ansible-doc -l
  $     ansible-doc -scommand
  2.ansible-galaxy
  参数详解:
[iyunv@localhost ~]#ansible-galaxy -h

  Usage: ansible-galaxy [init|info|install|list|remove] [--help] [options] ...
  Options:
  -h, --help  show thishelp message and exit
  See 'ansible-galaxy<command> --help' formore information on a specific command.
  特殊说明:
  ansible-galaxy 指令用于方便的从https://galaxy.ansible.com/ 站点下载第三方扩展模块,我们可以形象的理解其类似于centos下的yum、python下的pip或easy_install
  举例:
[iyunv@localhost ~]#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.dockerto /etc/ansible/roles/aeriscloud.docker
  - aeriscloud.docker wasinstalled successfully
  3.ansible-playbook
  参数详解:
[iyunv@localhost ~]#ansible-playbook -h

  Usage: ansible-playbook playbook.yml
  Options:
  -k, --ask-pass        ask forSSH password
  --ask-su-pass         ask forsu password
  -K, --ask-sudo-pass   ask forsudo password
  --ask-vault-pass      ask forvault password
  -C, --check           don't make anychanges; instead, try to predict some
  of the changesthat may occur
  -c CONNECTION, --connection=CONNECTION
  connection typeto use (default=smart)
  -D, --diff            when changing (small) files andtemplates, show the
  differences inthose files; works great with --check
  -e EXTRA_VARS, --extra-vars=EXTRA_VARS
  set additionalvariables as key=value or YAML/JSON
  --force-handlers      run handlers even if atask fails
  -f FORKS, --forks=FORKS
  specify number ofparallel processes to use
  (default=5)
  -h, --help            show thishelp message and exit
  -i INVENTORY,--inventory-file=INVENTORY
  specify inventoryhost file
  (default=/etc/ansible/hosts)
  -l SUBSET, --limit=SUBSET
  further limitselected 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 toauthenticate the connection
  --skip-tags=SKIP_TAGS
  only run playsand tasks whose tags do not match these
  values
  --start-at-task=START_AT
  start theplaybook at the task matching this name
  --step                one-step-at-a-time: confirmeach task before running
  -S, --su              run operations with su
  -R SU_USER, --su-user=SU_USER
  run operationswith 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 thesevalues
  -T TIMEOUT, --timeout=TIMEOUT
  overridethe SSH timeout in seconds (default=10)
  -u REMOTE_USER, --user=REMOTE_USER
  connect as thisuser (default=root)
  --vault-password-file=VAULT_PASSWORD_FILE
  vault passwordfile
  -v, --verbose         verbose mode (-vvv formore, -vvvv to enable
  connectiondebugging)
  --version             show program'sversion number and exit
  4.ansible-pull
  参数详解:
[iyunv@localhost ~]#ansible-pull -h

  Usage: ansible-pull [options] [playbook.yml]
  Options:
  -K, --ask-sudo-pass   ask forsudo password
  -C CHECKOUT, --checkout=CHECKOUT
  branch/tag/committo checkout.  Defaults to behavior
  of repositorymodule.
  -d DEST, --directory=DEST
  directory tocheckout repository to
  -e EXTRA_VARS, --extra-vars=EXTRA_VARS
  setadditional variables as key=value orYAML/JSON
  -f, --force           run the playbook even ifthe repository could not be
  updated
  -h, --help            show thishelp message and exit
  -i INVENTORY,--inventory-file=INVENTORY    指定库存主机文件的路径,默认为/etc/ansible/hosts
  location of theinventory host file
  -m MODULE_NAME,--module-name=MODULE_NAME   从仓库检查的模块名,默认是git
  Module name usedto check out repository.  Default is
  git.
  -o, --only-if-changed
  only run theplaybook if the repository has been
  updated
  --purge               purge checkout after playbookrun
  -s SLEEP, --sleep=SLEEP
  sleep for randominterval (between 0 and n number of
  seconds) beforestarting. this is auseful way to
  disperse gitrequests
  -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
  参数详解:
[iyunv@localhost ~]#ansible-vault

  Usage: ansible-vault [create|decrypt|edit|encrypt|rekey] [--help] [options]file_name
  Options:
  -h, --help  show thishelp message and exit
  See 'ansible-vault<command> --help' formore information on a specific command.
  特殊说明:
  ansible-vault主要应用于配置文件中含有敏感信息,又不希望他能被人看到,vault可以帮你加密/解密这个配置文件,属高级用法。主要对于playbooks里比如涉及到配置密码或其他变量时,可以通过该指令加密,这样我们通过cat看到的会是一个密码串类的文件,编辑的时候需要输入事先设定的密码才能打开。这种playbook文件在执行时,需要加上 –ask-vault-pass参数,同样需要输入密码后才能正常执行。具体该部分可以参查官方博客。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-430895-1-1.html 上篇帖子: Ansible 学习总结 下篇帖子: 自动化运维 -- 02 Ansible
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表