mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 11:51:26 -07:00
inventory group 'all' variables are global variables
applied to every host and available all over they are read in so that ones defined first can be used to define the later ones.
This commit is contained in:
parent
df61a65344
commit
dc35dd99c0
2 changed files with 36 additions and 10 deletions
|
@ -103,16 +103,20 @@ class PlayBook(object):
|
|||
self.sudo = sudo
|
||||
self.sudo_pass = sudo_pass
|
||||
self.extra_vars = extra_vars
|
||||
|
||||
self.basedir = os.path.dirname(playbook)
|
||||
self.playbook = self._parse_playbook(playbook)
|
||||
self.global_vars = {}
|
||||
|
||||
if override_hosts is not None:
|
||||
if type(override_hosts) != list:
|
||||
raise errors.AnsibleError("override hosts must be a list")
|
||||
self.global_vars.update(ansible.inventory.Inventory(host_list).get_global_vars())
|
||||
self.inventory = ansible.inventory.Inventory(override_hosts)
|
||||
|
||||
else:
|
||||
self.inventory = ansible.inventory.Inventory(host_list)
|
||||
self.global_vars.update(ansible.inventory.Inventory(host_list).get_global_vars())
|
||||
|
||||
self.basedir = os.path.dirname(playbook)
|
||||
self.playbook = self._parse_playbook(playbook)
|
||||
|
||||
# *****************************************************
|
||||
|
||||
|
@ -123,7 +127,7 @@ class PlayBook(object):
|
|||
play['vars'] = {}
|
||||
if type(play['vars']) not in [dict, list]:
|
||||
raise errors.AnsibleError("'vars' section must contain only key/value pairs")
|
||||
vars = {}
|
||||
vars = self.global_vars
|
||||
|
||||
# translate a list of vars into a dict
|
||||
if type(play['vars']) == list:
|
||||
|
@ -151,9 +155,9 @@ class PlayBook(object):
|
|||
''' load tasks included from external files. '''
|
||||
|
||||
# include: some.yml a=2 b=3 c=4
|
||||
include_tokens = task['include'].split()
|
||||
path = utils.path_dwim(dirname, include_tokens[0])
|
||||
play_vars = self._get_vars(play, dirname)
|
||||
include_tokens = utils.template(task['include'], play_vars, SETUP_CACHE).split()
|
||||
path = utils.path_dwim(dirname, include_tokens[0])
|
||||
include_vars = {}
|
||||
for i,x in enumerate(include_tokens):
|
||||
if x.find("=") != -1:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue