mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #6021 from risaacson/issue_5359_2
Config resoution order correction and documentation.
This commit is contained in:
commit
77c42c5c1e
3 changed files with 30 additions and 20 deletions
|
@ -5,17 +5,24 @@ The Ansible Configuration File
|
||||||
|
|
||||||
.. highlight:: bash
|
.. highlight:: bash
|
||||||
|
|
||||||
Certain things in Ansible are adjustable in a configuration file. In general, the stock configuration is probably
|
Certain settings in Ansible are adjustable via a configuration file. The stock configuration should be sufficient
|
||||||
right for most users, but that doesn't mean you might not want to change them.
|
for most users, but there may be reasons you would want to change them.
|
||||||
|
|
||||||
The mechanism for doing this is the "ansible.cfg" file, which is looked for in the following locations::
|
Changes can be made and used in a configuration file which will be processed processed in the following order::
|
||||||
|
|
||||||
* /etc/ansible/ansible.cfg
|
* ANSIBLE_CONFIG (an environment variable)
|
||||||
* ~/.ansible.cfg
|
|
||||||
* ansible.cfg (in the current directory)
|
* ansible.cfg (in the current directory)
|
||||||
|
* .ansible.cfg (in the home directory)
|
||||||
|
* /etc/ansible/ansible.cfg
|
||||||
|
|
||||||
If multiple file locations matching the above exist, the last location on the above list is used. Settings in files
|
Prior to 1.5 the order was::
|
||||||
are not merged together.
|
|
||||||
|
* ansible.cfg (in the current directory)
|
||||||
|
* ANSIBLE_CONFIG (an environment variable)
|
||||||
|
* .ansible.cfg (in the home directory)
|
||||||
|
* /etc/ansible/ansible.cfg
|
||||||
|
|
||||||
|
Ansible will process the above list and use the first file found. Settings in files are not merged together.
|
||||||
|
|
||||||
.. _getting_the_latest_configuration:
|
.. _getting_the_latest_configuration:
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,10 @@
|
||||||
# ==============================================
|
# ==============================================
|
||||||
|
|
||||||
# nearly all parameters can be overridden in ansible-playbook
|
# nearly all parameters can be overridden in ansible-playbook
|
||||||
# or with command line flags. ansible will read ~/.ansible.cfg,
|
# or with command line flags. ansible will read ANSIBLE_CONFIG,
|
||||||
# ansible.cfg in the current working directory or
|
# ansible.cfg in the current working directory, .ansible.cfg in
|
||||||
# /etc/ansible/ansible.cfg, whichever it finds first
|
# the home directory or /etc/ansible/ansible.cfg, whichever it
|
||||||
|
# finds first
|
||||||
|
|
||||||
[defaults]
|
[defaults]
|
||||||
|
|
||||||
|
|
|
@ -56,20 +56,22 @@ def _get_config(p, section, key, env_var, default):
|
||||||
return default
|
return default
|
||||||
|
|
||||||
def load_config_file():
|
def load_config_file():
|
||||||
|
''' Load Config File order(first found is used): ENV, CWD, HOME, /etc/ansible '''
|
||||||
|
|
||||||
p = ConfigParser.ConfigParser()
|
p = ConfigParser.ConfigParser()
|
||||||
|
|
||||||
|
path0 = os.getenv("ANSIBLE_CONFIG", None)
|
||||||
|
if path0 is not None:
|
||||||
|
path0 = os.path.expanduser(path0)
|
||||||
path1 = os.getcwd() + "/ansible.cfg"
|
path1 = os.getcwd() + "/ansible.cfg"
|
||||||
path2 = os.path.expanduser(os.environ.get('ANSIBLE_CONFIG', "~/.ansible.cfg"))
|
path2 = os.path.expanduser("~/.ansible.cfg")
|
||||||
path3 = "/etc/ansible/ansible.cfg"
|
path3 = "/etc/ansible/ansible.cfg"
|
||||||
|
|
||||||
if os.path.exists(path1):
|
for path in [path0, path1, path2, path3]:
|
||||||
p.read(path1)
|
if path is not None and os.path.exists(path):
|
||||||
elif os.path.exists(path2):
|
p.read(path)
|
||||||
p.read(path2)
|
|
||||||
elif os.path.exists(path3):
|
|
||||||
p.read(path3)
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
return p
|
return p
|
||||||
|
return None
|
||||||
|
|
||||||
def shell_expand_path(path):
|
def shell_expand_path(path):
|
||||||
''' shell_expand_path is needed as os.path.expanduser does not work
|
''' shell_expand_path is needed as os.path.expanduser does not work
|
||||||
|
|
Loading…
Reference in a new issue