1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Tweaks on previous refactoring of playbook, version bump a 0.4 reference, remove some debug, etc

This commit is contained in:
Michael DeHaan 2012-05-26 01:20:53 -04:00
parent b9b53d1941
commit ecb944892d
6 changed files with 27 additions and 27 deletions

View file

@ -14,5 +14,5 @@
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
__version__ = '0.4'
__version__ = '0.5'
__author__ = 'Michael DeHaan'

View file

@ -33,6 +33,9 @@ class Play(object):
# *************************************************
def __init__(self, playbook, ds):
''' constructor loads from a play datastructure '''
# TODO: more error handling
self._ds = ds
self.playbook = playbook
@ -90,16 +93,20 @@ class Play(object):
# *************************************************
def handlers(self):
return self._handlers
def tasks(self):
''' return task objects for this play '''
return self._tasks
def handlers(self):
''' return handler objects for this play '''
return self._handlers
# *************************************************
def _get_vars(self, dirname):
''' load the vars section from a play '''
''' load the vars section from a play, accounting for all sorts of variable features
including loading from yaml files, prompting, and conditional includes of the first
file found in a list. '''
if self.vars is None:
self.vars = {}
@ -120,8 +127,7 @@ class Play(object):
if type(self.vars_prompt) != dict:
raise errors.AnsibleError("'vars_prompt' section must contain only key/value pairs")
for vname in self.vars_prompt:
# TODO: make this prompt one line and consider double entry
vars[vname] = self.callbacks.on_vars_prompt(vname)
vars[vname] = self.playbook.callbacks.on_vars_prompt(vname)
results = self.playbook.extra_vars.copy()
results.update(vars)
@ -132,18 +138,17 @@ class Play(object):
def update_vars_files(self, hosts):
''' calculate vars_files, which requires that setup runs first so ansible facts can be mixed in '''
for h in hosts:
self.update_vars_files_for_host(h)
self._update_vars_files_for_host(h)
# *************************************************
def update_vars_files_for_host(self, host):
def _update_vars_files_for_host(self, host):
if not host in self.playbook.SETUP_CACHE:
# no need to process failed hosts or hosts not in this play
return
for filename in self.vars_files:
# TODO: maybe have to template the path here...
if type(filename) == list:

View file

@ -17,11 +17,7 @@
#############################################
#import ansible.inventory
#import ansible.runner
#import ansible.constants as C
#from ansible import utils
#from ansible import errors
from ansible import errors
class Task(object):
@ -31,12 +27,11 @@ class Task(object):
]
def __init__(self, play, ds):
''' constructor loads from a task or handler datastructure '''
# TODO: more error handling
self.play = play
# FIXME: error handling on invalid fields
# action...
self.name = ds.get('name', None)
self.action = ds.get('action', '')
self.notified_by = []
@ -53,8 +48,7 @@ class Task(object):
tokens = self.action.split(None, 1)
if len(tokens) < 1:
# FIXME: better error handling
raise Exception("invalid action in task: %s" % ds)
raise errors.AnsibleError("invalid/missing action in task")
self.module_name = tokens[0]
self.module_args = ''
@ -63,6 +57,7 @@ class Task(object):
# include task specific vars
self.module_vars = ds.get('vars', {})
if 'first_available_file' in ds:
self.module_vars['first_available_file'] = ds.get('first_available_file')

View file

@ -549,6 +549,9 @@ class Runner(object):
return ReturnData(host=conn.host, comm_ok=False, result=result)
if self.module_vars is not None:
inject.update(self.module_vars)
source = utils.template(source, inject, self.setup_cache)
#(host, ok, data, err) = (None, None, None, None)

View file

@ -42,15 +42,13 @@ with warnings.catch_warnings():
class Connection(object):
''' Handles abstract connections to remote hosts '''
_LOCALHOSTRE = re.compile(r"^(127.0.0.1|localhost|%s)$" % os.uname()[1])
def __init__(self, runner, transport,sudo_user):
self.runner = runner
self.transport = transport
self.sudo_user = sudo_user
def connect(self, host, port=None):
conn = None
if self.transport == 'local' and self._LOCALHOSTRE.search(host):
if self.transport == 'local':
conn = LocalConnection(self.runner, host)
elif self.transport == 'paramiko':
conn = ParamikoConnection(self.runner, host, port)

View file

@ -124,7 +124,6 @@ class LibvirtConnection(object):
def get_status2(self, vm):
state = vm.info()[0]
# print "DEBUG: state: %s" % state
return VIRT_STATE_NAME_MAP.get(state,"unknown")
def get_status(self, vmid):