~canonical-ci-engineering/ubuntu-ci-services-itself/ansible

« back to all changes in this revision

Viewing changes to lib/ansible/runner/__init__.py

  • Committer: Package Import Robot
  • Author(s): Harlan Lieberman-Berg
  • Date: 2014-04-01 22:00:24 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20140401220024-jkxyhf2ggcv7xmqa
Tags: 1.5.4+dfsg-1
* Pull missing manpages from upstream development branch.
* New upstream version 1.5.4, security update.
* Add patch to correct directory_mode functionality. (Closes: #743027)

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
            traceback.print_exc()
87
87
 
88
88
class HostVars(dict):
89
 
    ''' A special view of setup_cache that adds values from the inventory when needed. '''
 
89
    ''' A special view of vars_cache that adds values from the inventory when needed. '''
90
90
 
91
 
    def __init__(self, setup_cache, inventory):
92
 
        self.setup_cache = setup_cache
 
91
    def __init__(self, vars_cache, inventory):
 
92
        self.vars_cache = vars_cache
93
93
        self.inventory = inventory
94
94
        self.lookup = dict()
95
 
        self.update(setup_cache)
 
95
        self.update(vars_cache)
96
96
 
97
97
    def __getitem__(self, host):
98
98
        if host not in self.lookup:
99
99
            result = self.inventory.get_variables(host)
100
 
            result.update(self.setup_cache.get(host, {}))
 
100
            result.update(self.vars_cache.get(host, {}))
101
101
            self.lookup[host] = result
102
102
        return self.lookup[host]
103
103
 
123
123
        background=0,                       # async poll every X seconds, else 0 for non-async
124
124
        basedir=None,                       # directory of playbook, if applicable
125
125
        setup_cache=None,                   # used to share fact data w/ other tasks
 
126
        vars_cache=None,                    # used to store variables about hosts
126
127
        transport=C.DEFAULT_TRANSPORT,      # 'ssh', 'paramiko', 'local'
127
128
        conditional='True',                 # run only if this fact expression evals to true
128
129
        callbacks=None,                     # used for output
160
161
        self.check            = check
161
162
        self.diff             = diff
162
163
        self.setup_cache      = utils.default(setup_cache, lambda: collections.defaultdict(dict))
 
164
        self.vars_cache       = utils.default(vars_cache, lambda: collections.defaultdict(dict))
163
165
        self.basedir          = utils.default(basedir, lambda: os.getcwd())
164
166
        self.callbacks        = utils.default(callbacks, lambda: DefaultRunnerCallbacks())
165
167
        self.generated_jid    = str(random.randint(0, 999999999999))
559
561
            # fireball, local, etc
560
562
            port = self.remote_port
561
563
 
 
564
        module_vars = template.template(self.basedir, self.module_vars, host_variables)
 
565
 
 
566
        # merge the VARS and SETUP caches for this host
 
567
        combined_cache = self.setup_cache.copy()
 
568
        combined_cache.get(host, {}).update(self.vars_cache.get(host, {}))
 
569
 
562
570
        inject = {}
563
571
        inject = utils.combine_vars(inject, self.default_vars)
564
572
        inject = utils.combine_vars(inject, host_variables)
565
 
        inject = utils.combine_vars(inject, self.module_vars)
566
 
        inject = utils.combine_vars(inject, self.setup_cache[host])
 
573
        inject = utils.combine_vars(inject, module_vars)
 
574
        inject = utils.combine_vars(inject, combined_cache.get(host, {}))
567
575
        inject.setdefault('ansible_ssh_user', self.remote_user)
568
 
        inject['hostvars'] = HostVars(self.setup_cache, self.inventory)
 
576
        inject['hostvars'] = HostVars(combined_cache, self.inventory)
569
577
        inject['group_names'] = host_variables.get('group_names', [])
570
578
        inject['groups']      = self.inventory.groups_list()
571
579
        inject['vars']        = self.module_vars