天天看点

ansible配置文件管理

文章目录

    • 4. 管理ansible的配置文件
      • 4.1 ansible配置文件的分类
      • 4.2 配置文件的优先级
    • 5. 如何查看帮助文档

4. 管理ansible的配置文件

4.1 ansible配置文件的分类

ANSIBLE_CONFIG:首先ansible会检查当前的环境变量,及这个环境变量指向的配置文件ANSIBLE_CONFIG。定义了此变量时,Ansible将使用变量所指定的配置文件,而不用其他任何配置文件。

./ansible.cfg:如果没有设置该变量的情况下则会去查找当前运行ansible的目录中是否有ansible.cfg文件。

~/ansible.cfg:如果在当前运行ansible的目录中没有找到ansible文件的话则会去查找家目录中是否有ansible.cfg文件

/etc/ansible/ansible.cfg:最后如果家目录下没有此文件的话将会检查在安装Ansible时自动生产的配置文件。

4.2 配置文件的优先级

ANSIBLE_CONFIG > 当前目录下的ansible.cfg > ~/.ansible.cfg > /etc/ansible/ansible.cfg

5. 如何查看帮助文档

ansible拥有上千个插件和模块,可以实现各种软件、平台 、版本的管理,并且支持虚拟容器的多层级的部署

可以通过以下命令查看ansible模块和插件的帮助文档

[[email protected] ansible]# ansible-doc
usage: ansible-doc [-h] [--version] [-v] [-M MODULE_PATH]
                   [--playbook-dir BASEDIR]
                   [-t {become,cache,callback,cliconf,connection,httpapi,inventory,lookup,netconf,shell,module,strategy,vars}]
                   [-j] [-F | -l | -s | --metadata-dump]
                   [plugin [plugin ...]]

plugin documentation tool

positional arguments:
  plugin                Plugin

optional arguments:
  --metadata-dump       **For internal testing only** Dump json metadata for
                        all plugins.
  --playbook-dir BASEDIR
                        Since this tool does not use playbooks, use this as a
                        substitute playbook directory.This sets the relative
                        path for many features including roles/ group_vars/
                        etc.
  --version             show program's version number, config file location,
                        configured module search path, module location,
                        executable location and exit
  -F, --list_files      Show plugin names and their source files without
                        summaries (implies --list)
  -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)
  -h, --help            show this help message and exit
  -j, --json            Change output into json format.
  -l, --list            List available plugins
  -s, --snippet         Show playbook snippet for specified plugin(s)
  -t {become,cache,callback,cliconf,connection,httpapi,inventory,lookup,netconf,shell,module,strategy,vars}, --type {become,cache,callback,cliconf,connection,httpapi,inventory,lookup,netconf,shell,module,strategy,vars}
                        Choose which plugin type (defaults to "module").
                        Available plugin types are : ('become', 'cache',
                        'callback', 'cliconf', 'connection', 'httpapi',
                        'inventory', 'lookup', 'netconf', 'shell', 'module',
                        'strategy', 'vars')
  -v, --verbose         verbose mode (-vvv for more, -vvvv to enable
                        connection debugging)

See man pages for Ansible CLI options or website for tutorials
https://docs.ansible.com

           

也可以直接官网进行查看帮助文档