From 61d064d011b47c522d77ef736d6d67470fb0f977 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Sun, 26 Feb 2012 19:55:26 -0500 Subject: [PATCH] Fixed up KV munging in runner, misc fixes to copy, setup, and template modules --- examples/playbook.yml | 5 ++++- lib/ansible/playbook.py | 37 ++++++++----------------------------- lib/ansible/runner.py | 10 +++++----- library/copy | 1 + library/setup | 3 ++- library/template | 1 + 6 files changed, 21 insertions(+), 36 deletions(-) diff --git a/examples/playbook.yml b/examples/playbook.yml index e9b6d9b795..5e4b8d6c2c 100644 --- a/examples/playbook.yml +++ b/examples/playbook.yml @@ -1,6 +1,9 @@ - pattern: '*' - hosts: '/etc/ansible/hosts' + hosts: /etc/ansible/hosts tasks: + - do: + - restart apache for kicks + - command /sbin/service apache restart - do: - configure template & module variables for future template calls - setup a=2 b=3 c=4 diff --git a/lib/ansible/playbook.py b/lib/ansible/playbook.py index d8a5437947..98c06f131c 100755 --- a/lib/ansible/playbook.py +++ b/lib/ansible/playbook.py @@ -88,32 +88,6 @@ class PlayBook(object): } return results - def _get_task_runner(self, - pattern=None, - host_list=None, - module_name=None, - module_args=None): - - ''' - return a runner suitable for running this task, using - preferences from the constructor - ''' - - if host_list is None: - host_list = self.host_list - - return ansible.runner.Runner( - pattern=pattern, - module_name=module_name, - module_args=module_args, - host_list=host_list, - forks=self.forks, - remote_user=self.remote_user, - remote_pass=self.remote_pass, - module_path=self.module_path, - timeout=self.timeout - ) - def _run_task(self, pattern=None, task=None, host_list=None, handlers=None, conditional=False): ''' run a single task in the playbook and @@ -135,11 +109,16 @@ class PlayBook(object): else: print "\nNOTIFIED [%s]" % (comment) - runner = self._get_task_runner( + runner = ansible.runner.Runner( pattern=pattern, - host_list=host_list, module_name=module_name, - module_args=module_args + module_args=module_args, + host_list=host_list, + forks=self.forks, + remote_user=self.remote_user, # FIXME: read from playbook + remote_pass=self.remote_pass, + module_path=self.module_path, + timeout=self.timeout ) results = runner.run() diff --git a/lib/ansible/runner.py b/lib/ansible/runner.py index 8c4f755245..526e743327 100755 --- a/lib/ansible/runner.py +++ b/lib/ansible/runner.py @@ -154,17 +154,17 @@ class Runner(object): options = self._parse_kv(self.module_args) source = options['src'] dest = options['dest'] - tmp_dest = self._get_tmp_path(conn, dest.split("/")[-1]) - self._transfer_file(conn, source, tmp_dest) + tmp_src = self._get_tmp_path(conn, dest.split("/")[-1]) + self._transfer_file(conn, source, tmp_src) # install the copy module self.module_name = 'copy' module = self._transfer_module(conn) # run the copy module - self.module_args = [ tmp_dest, dest ] + self.module_args = [ "src=%s" % tmp_src, "dest=%s" % dest ] result = self._execute_module(conn, module) - self._delete_remote_files(conn, tmp_dest) + self._delete_remote_files(conn, tmp_src) return self._return_from_module(conn, host, result) def _execute_template(self, conn, host): @@ -185,7 +185,7 @@ class Runner(object): module = self._transfer_module(conn) # run the template module - self.module_args = [ temppath, dest, metadata ] + self.module_args = [ "src=%s" % temppath, "dest=%s" % dest, "metadata=%s" % metadata ] result = self._execute_module(conn, module) self._delete_remote_files(conn, [ temppath ]) return self._return_from_module(conn, host, result) diff --git a/library/copy b/library/copy index 95b70ee1a4..a7514fe27b 100644 --- a/library/copy +++ b/library/copy @@ -2,6 +2,7 @@ import sys import os +import shlex try: import json diff --git a/library/setup b/library/setup index 5e9fccbf35..4d93fba9e1 100755 --- a/library/setup +++ b/library/setup @@ -16,7 +16,7 @@ except ImportError: input_data = sys.argv[1:] new_options = dict([ x.split('=') for x in input_data ]) ansible_file = new_options.get('metadata', DEFAULT_ANSIBLE_SETUP) -ansible_dir = os.path.dirname(metadata) +ansible_dir = os.path.dirname(ansible_file) # create the config dir if it doesn't exist @@ -24,6 +24,7 @@ if not os.path.exists(ansible_dir): os.makedirs(ansible_dir) changed = False +md5sum = None if not os.path.exists(ansible_file): changed = True else: diff --git a/library/template b/library/template index d77c5cef92..4ce579c78b 100644 --- a/library/template +++ b/library/template @@ -3,6 +3,7 @@ import sys import os import jinja2 +import shlex try: import json except ImportError: