mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fixed up KV munging in runner, misc fixes to copy, setup, and template modules
This commit is contained in:
parent
226da501d3
commit
61d064d011
6 changed files with 21 additions and 36 deletions
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import sys
|
||||
import os
|
||||
import shlex
|
||||
|
||||
try:
|
||||
import json
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
import sys
|
||||
import os
|
||||
import jinja2
|
||||
import shlex
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
|
|
Loading…
Reference in a new issue