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:
parent
b9b53d1941
commit
ecb944892d
6 changed files with 27 additions and 27 deletions
|
@ -14,5 +14,5 @@
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
__version__ = '0.4'
|
__version__ = '0.5'
|
||||||
__author__ = 'Michael DeHaan'
|
__author__ = 'Michael DeHaan'
|
||||||
|
|
|
@ -33,6 +33,9 @@ class Play(object):
|
||||||
# *************************************************
|
# *************************************************
|
||||||
|
|
||||||
def __init__(self, playbook, ds):
|
def __init__(self, playbook, ds):
|
||||||
|
''' constructor loads from a play datastructure '''
|
||||||
|
|
||||||
|
# TODO: more error handling
|
||||||
|
|
||||||
self._ds = ds
|
self._ds = ds
|
||||||
self.playbook = playbook
|
self.playbook = playbook
|
||||||
|
@ -90,16 +93,20 @@ class Play(object):
|
||||||
|
|
||||||
# *************************************************
|
# *************************************************
|
||||||
|
|
||||||
def handlers(self):
|
|
||||||
return self._handlers
|
|
||||||
|
|
||||||
def tasks(self):
|
def tasks(self):
|
||||||
|
''' return task objects for this play '''
|
||||||
return self._tasks
|
return self._tasks
|
||||||
|
|
||||||
|
def handlers(self):
|
||||||
|
''' return handler objects for this play '''
|
||||||
|
return self._handlers
|
||||||
|
|
||||||
# *************************************************
|
# *************************************************
|
||||||
|
|
||||||
def _get_vars(self, dirname):
|
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:
|
if self.vars is None:
|
||||||
self.vars = {}
|
self.vars = {}
|
||||||
|
@ -120,8 +127,7 @@ class Play(object):
|
||||||
if type(self.vars_prompt) != dict:
|
if type(self.vars_prompt) != dict:
|
||||||
raise errors.AnsibleError("'vars_prompt' section must contain only key/value pairs")
|
raise errors.AnsibleError("'vars_prompt' section must contain only key/value pairs")
|
||||||
for vname in self.vars_prompt:
|
for vname in self.vars_prompt:
|
||||||
# TODO: make this prompt one line and consider double entry
|
vars[vname] = self.playbook.callbacks.on_vars_prompt(vname)
|
||||||
vars[vname] = self.callbacks.on_vars_prompt(vname)
|
|
||||||
|
|
||||||
results = self.playbook.extra_vars.copy()
|
results = self.playbook.extra_vars.copy()
|
||||||
results.update(vars)
|
results.update(vars)
|
||||||
|
@ -132,18 +138,17 @@ class Play(object):
|
||||||
def update_vars_files(self, hosts):
|
def update_vars_files(self, hosts):
|
||||||
''' calculate vars_files, which requires that setup runs first so ansible facts can be mixed in '''
|
''' calculate vars_files, which requires that setup runs first so ansible facts can be mixed in '''
|
||||||
for h in hosts:
|
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:
|
if not host in self.playbook.SETUP_CACHE:
|
||||||
# no need to process failed hosts or hosts not in this play
|
# no need to process failed hosts or hosts not in this play
|
||||||
return
|
return
|
||||||
|
|
||||||
for filename in self.vars_files:
|
for filename in self.vars_files:
|
||||||
# TODO: maybe have to template the path here...
|
|
||||||
|
|
||||||
if type(filename) == list:
|
if type(filename) == list:
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,7 @@
|
||||||
|
|
||||||
#############################################
|
#############################################
|
||||||
|
|
||||||
#import ansible.inventory
|
from ansible import errors
|
||||||
#import ansible.runner
|
|
||||||
#import ansible.constants as C
|
|
||||||
#from ansible import utils
|
|
||||||
#from ansible import errors
|
|
||||||
|
|
||||||
class Task(object):
|
class Task(object):
|
||||||
|
|
||||||
|
@ -31,12 +27,11 @@ class Task(object):
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, play, ds):
|
def __init__(self, play, ds):
|
||||||
|
''' constructor loads from a task or handler datastructure '''
|
||||||
|
|
||||||
|
# TODO: more error handling
|
||||||
|
|
||||||
self.play = play
|
self.play = play
|
||||||
|
|
||||||
# FIXME: error handling on invalid fields
|
|
||||||
# action...
|
|
||||||
|
|
||||||
self.name = ds.get('name', None)
|
self.name = ds.get('name', None)
|
||||||
self.action = ds.get('action', '')
|
self.action = ds.get('action', '')
|
||||||
self.notified_by = []
|
self.notified_by = []
|
||||||
|
@ -53,8 +48,7 @@ class Task(object):
|
||||||
|
|
||||||
tokens = self.action.split(None, 1)
|
tokens = self.action.split(None, 1)
|
||||||
if len(tokens) < 1:
|
if len(tokens) < 1:
|
||||||
# FIXME: better error handling
|
raise errors.AnsibleError("invalid/missing action in task")
|
||||||
raise Exception("invalid action in task: %s" % ds)
|
|
||||||
|
|
||||||
self.module_name = tokens[0]
|
self.module_name = tokens[0]
|
||||||
self.module_args = ''
|
self.module_args = ''
|
||||||
|
@ -63,6 +57,7 @@ class Task(object):
|
||||||
|
|
||||||
# include task specific vars
|
# include task specific vars
|
||||||
self.module_vars = ds.get('vars', {})
|
self.module_vars = ds.get('vars', {})
|
||||||
|
|
||||||
if 'first_available_file' in ds:
|
if 'first_available_file' in ds:
|
||||||
self.module_vars['first_available_file'] = ds.get('first_available_file')
|
self.module_vars['first_available_file'] = ds.get('first_available_file')
|
||||||
|
|
||||||
|
|
|
@ -549,6 +549,9 @@ class Runner(object):
|
||||||
return ReturnData(host=conn.host, comm_ok=False, result=result)
|
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)
|
source = utils.template(source, inject, self.setup_cache)
|
||||||
|
|
||||||
#(host, ok, data, err) = (None, None, None, None)
|
#(host, ok, data, err) = (None, None, None, None)
|
||||||
|
|
|
@ -42,15 +42,13 @@ with warnings.catch_warnings():
|
||||||
class Connection(object):
|
class Connection(object):
|
||||||
''' Handles abstract connections to remote hosts '''
|
''' 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):
|
def __init__(self, runner, transport,sudo_user):
|
||||||
self.runner = runner
|
self.runner = runner
|
||||||
self.transport = transport
|
self.transport = transport
|
||||||
self.sudo_user = sudo_user
|
self.sudo_user = sudo_user
|
||||||
def connect(self, host, port=None):
|
def connect(self, host, port=None):
|
||||||
conn = None
|
conn = None
|
||||||
if self.transport == 'local' and self._LOCALHOSTRE.search(host):
|
if self.transport == 'local':
|
||||||
conn = LocalConnection(self.runner, host)
|
conn = LocalConnection(self.runner, host)
|
||||||
elif self.transport == 'paramiko':
|
elif self.transport == 'paramiko':
|
||||||
conn = ParamikoConnection(self.runner, host, port)
|
conn = ParamikoConnection(self.runner, host, port)
|
||||||
|
|
|
@ -124,7 +124,6 @@ class LibvirtConnection(object):
|
||||||
|
|
||||||
def get_status2(self, vm):
|
def get_status2(self, vm):
|
||||||
state = vm.info()[0]
|
state = vm.info()[0]
|
||||||
# print "DEBUG: state: %s" % state
|
|
||||||
return VIRT_STATE_NAME_MAP.get(state,"unknown")
|
return VIRT_STATE_NAME_MAP.get(state,"unknown")
|
||||||
|
|
||||||
def get_status(self, vmid):
|
def get_status(self, vmid):
|
||||||
|
|
Loading…
Reference in a new issue