ansible

   参数详解:

  1. [root@localhost ~]# ansible
  2. Usage: ansible <host-pattern> [options]
  3. Options:
  4. -a MODULE_ARGS, --args=MODULE_ARGS 模块的参数,如果执行默认COMMAND的模块,即是命令参数,如:“date”,"pwd"等等
  5. module arguments 模块参数
  6. -k, --ask-pass ask for SSH password 登录密码,提示输入SSH密码而不是假设基于密钥的验证
  7. --ask-su-pass ask for su password su切换密码
  8. -K, --ask-sudo-pass ask for sudo password 提示密码使用sudo,sudo表示提权操作
  9. --ask-vault-pass ask for vault password
  10. -B SECONDS, --background=SECONDS 后台运行超时时间
  11. run asynchronously, failing after X seconds
  12. (default=N/A)
  13. -C, --check don't make any changes; instead, try to predict some 只是测试一下会改变什么内容,不会真正去执行;相反,试图预测一些可能发生的变化
  14. of the changes that may occur
  15. -c CONNECTION, --connection=CONNECTION 连接类型使用。可能的选项是paramiko(SSH),SSH和地方。当地主要是用于crontab或启动。
  16. connection type to use (default=smart)
  17. -f FORKS, --forks=FORKS 并行任务数。NUM被指定为一个整数,默认是5
  18. specify number of parallel processes to use
  19. (default=5)
  20. -h, --help show this help message and exit 打开帮助文档API
  21. -i INVENTORY, --inventory-file=INVENTORY 指定库存主机文件的路径,默认为/etc/ansible/hosts
  22. specify inventory host file
  23. (default=/etc/ansible/hosts)
  24. -l SUBSET, --limit=SUBSET 进一步限制所选主机/组模式 --limit=192.168.91.135 只对这个ip执行
  25. further limit selected hosts to an additional pattern
  26. --list-hosts outputs a list of matching hosts; does not execute
  27. anything else
  28. -m MODULE_NAME, --module-name=MODULE_NAME 执行模块的名字,默认使用 command 模块,所以如果是只执行单一命令可以不用 -m参数
  29. module name to execute (default=command)
  30. -M MODULE_PATH, --module-path=MODULE_PATH 要执行的模块的路径,默认为/usr/share/ansible/
  31. specify path(s) to module library
  32. (default=/usr/share/ansible/)
  33. -o, --one-line condense output 压缩输出,摘要输出.尝试一切都在一行上输出。
  34. -P POLL_INTERVAL, --poll=POLL_INTERVAL 调查背景工作每隔数秒。需要- b
  35. set the poll interval if using -B (default=15)
  36. --private-key=PRIVATE_KEY_FILE 私钥路径,使用这个文件来验证连接
  37. use this file to authenticate the connection
  38. -S, --su run operations with su 用 su 命令
  39. -R SU_USER, --su-user=SU_USER 指定SU的用户,默认是root用户
  40. run operations with su as this user (default=root)
  41. -s, --sudo run operations with sudo (nopasswd)
  42. -U SUDO_USER, --sudo-user=SUDO_USER sudo到哪个用户,默认为 root
  43. desired sudo user (default=root)
  44. -T TIMEOUT, --timeout=TIMEOUT 指定SSH默认超时时间, 默认是10S
  45. override the SSH timeout in seconds (default=10)
  46. -t TREE, --tree=TREE log output to this directory 将日志内容保存在该输出目录,结果保存在一个文件中在每台主机上。
  47. -u REMOTE_USER, --user=REMOTE_USER 远程用户, 默认是root用户
  48. connect as this user (default=root)
  49. --vault-password-file=VAULT_PASSWORD_FILE
  50. vault password file
  51. -v, --verbose verbose mode (-vvv for more, -vvvv to enable 详细信息
  52. connection debugging)
  53. --version show program's version number and exit 输出ansible的版本

特殊说明:

  1. ansible是指令核心部分,其主要用于执行ad-hoc(点对点)命令,即单条命令。默认后面需要跟主机和选项部分,默认不指定模块时,使用的是command模块。

  2. 默认使用的模块是可以在ansible.cfg 中进行修改的。 /etc/ansible/ansible.cfg

举例:

[root@localhost ~]# ansible 192.168.91.137 -a ‘pwd’
192.168.91.137 | success | rc=0 >>
/root

ansible-doc

   参数详解:

  1. [root@localhost ~]# ansible-doc -h
  2. Usage: ansible-doc [options] [module...]
  3. Show Ansible module documentation 显示Ansible模块文档
  4. Options:
  5. --version show program's version number and exit 显示ansible-doc的版本号
  6. -h, --help show this help message and exit 显示命令参数API文档
  7. -M MODULE_PATH, --module-path=MODULE_PATH 查询模块,--module-path=MODULE_PATH 指定模块的路径
  8. Ansible modules/ directory
  9. -l, --list List available modules 显示已存在的所有模块列表
  10. -s, --snippet Show playbook snippet for specified module(s) 显示playbook制定模块的用法
  11. -v Show version number and exit 显示ansible-doc的版本号

   举例:

      $ ansible-doc -l
      $ ansible-doc -s command

ansible-galaxy

参数详解:

  1. [root@localhost ~]# ansible-galaxy -h
  2. Usage: ansible-galaxy [init|info|install|list|remove] [--help] [options] ...
  3. Options:
  4. -h, --help show this help message and exit
  5. See 'ansible-galaxy <command> --help' for more information on a specific command.


特殊说明:

ansible-galaxy 指令用于方便的从https://galaxy.ansible.com/ 站点下载第三方扩展模块,我们可以形象的理解其类似于centos下的yum、python下的pip或easy_install

举例:

[root@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.docker to /etc/ansible/roles/aeriscloud.docker
- aeriscloud.docker was installed successfully

ansible-playbook

 参数详解:

  1. [root@localhost ~]# ansible-playbook -h
  2. Usage: ansible-playbook playbook.yml
  3. Options:
  4. -k, --ask-pass ask for SSH password
  5. --ask-su-pass ask for su password
  6. -K, --ask-sudo-pass ask for sudo password
  7. --ask-vault-pass ask for vault password
  8. -C, --check don't make any changes; instead, try to predict some
  9. of the changes that may occur
  10. -c CONNECTION, --connection=CONNECTION
  11. connection type to use (default=smart)
  12. -D, --diff when changing (small) files and templates, show the
  13. differences in those files; works great with --check
  14. -e EXTRA_VARS, --extra-vars=EXTRA_VARS
  15. set additional variables as key=value or YAML/JSON
  16. --force-handlers run handlers even if a task fails
  17. -f FORKS, --forks=FORKS
  18. specify number of parallel processes to use
  19. (default=5)
  20. -h, --help show this help message and exit
  21. -i INVENTORY, --inventory-file=INVENTORY
  22. specify inventory host file
  23. (default=/etc/ansible/hosts)
  24. -l SUBSET, --limit=SUBSET
  25. further limit selected hosts to an additional pattern
  26. --list-hosts outputs a list of matching hosts; does not execute
  27. anything else
  28. --list-tasks list all tasks that would be executed
  29. -M MODULE_PATH, --module-path=MODULE_PATH
  30. specify path(s) to module library
  31. (default=/usr/share/ansible/)
  32. --private-key=PRIVATE_KEY_FILE
  33. use this file to authenticate the connection
  34. --skip-tags=SKIP_TAGS
  35. only run plays and tasks whose tags do not match these
  36. values
  37. --start-at-task=START_AT
  38. start the playbook at the task matching this name
  39. --step one-step-at-a-time: confirm each task before running
  40. -S, --su run operations with su
  41. -R SU_USER, --su-user=SU_USER
  42. run operations with su as this user (default=root)
  43. -s, --sudo run operations with sudo (nopasswd)
  44. -U SUDO_USER, --sudo-user=SUDO_USER
  45. desired sudo user (default=root)
  46. --syntax-check perform a syntax check on the playbook, but do not
  47. execute it
  48. -t TAGS, --tags=TAGS only run plays and tasks tagged with these values
  49. -T TIMEOUT, --timeout=TIMEOUT
  50. override the SSH timeout in seconds (default=10)
  51. -u REMOTE_USER, --user=REMOTE_USER
  52. connect as this user (default=root)
  53. --vault-password-file=VAULT_PASSWORD_FILE
  54. vault password file
  55. -v, --verbose verbose mode (-vvv for more, -vvvv to enable
  56. connection debugging)
  57. --version show program's version number and exit

ansible-pull

  参数详解:

  1. [root@localhost ~]# ansible-pull -h
  2. Usage: ansible-pull [options] [playbook.yml]
  3. Options:
  4. -K, --ask-sudo-pass ask for sudo password
  5. -C CHECKOUT, --checkout=CHECKOUT
  6. branch/tag/commit to checkout. Defaults to behavior
  7. of repository module.
  8. -d DEST, --directory=DEST
  9. directory to checkout repository to
  10. -e EXTRA_VARS, --extra-vars=EXTRA_VARS
  11. set additional variables as key=value or YAML/JSON
  12. -f, --force run the playbook even if the repository could not be
  13. updated
  14. -h, --help show this help message and exit
  15. -i INVENTORY, --inventory-file=INVENTORY 指定库存主机文件的路径,默认为/etc/ansible/hosts
  16. location of the inventory host file
  17. -m MODULE_NAME, --module-name=MODULE_NAME 从仓库检查的模块名,默认是git
  18. Module name used to check out repository. Default is
  19. git.
  20. -o, --only-if-changed
  21. only run the playbook if the repository has been
  22. updated
  23. --purge purge checkout after playbook run
  24. -s SLEEP, --sleep=SLEEP
  25. sleep for random interval (between 0 and n number of
  26. seconds) before starting. this is a useful way to
  27. disperse git requests
  28. -U URL, --url=URL URL of the playbook repository
  29. --vault-password-file=VAULT_PASSWORD_FILE
  30. vault password file
  31. -v, --verbose Pass -vvvv to ansible-playbook

ansible-vault

  参数详解:

  1. [root@localhost ~]# ansible-vault
  2. Usage: ansible-vault [create|decrypt|edit|encrypt|rekey] [--help] [options] file_name
  3. Options:
  4. -h, --help show this help message and exit
  5. See 'ansible-vault <command> --help' for more information on a specific command.

特殊说明:

  ansible-vault主要应用于配置文件中含有敏感信息,又不希望他能被人看到,vault可以帮你加密/解密这个配置文件,属高级用法。主要对于playbooks里比如涉及到配置密码或其他变量时,可以通过该指令加密,这样我们通过cat看到的会是一个密码串类的文件,编辑的时候需要输入事先设定的密码才能打开。这种playbook文件在执行时,需要加上 –ask-vault-pass参数,同样需要输入密码后才能正常执行。具体该部分可以参查官方博客

参考资料

  ansible中文权威指南:
  http://www.ansible.com.cn/

  ansible小结(二):ansible结构:
  http://ju.outofmemory.cn/entry/143179