mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
src= parameters for template and copy operations can be relative to the playbook (for /usr/bin/ansible-playbook) or current directory (for /usr/bin/ansible)
This commit is contained in:
parent
7eedc3fb1a
commit
8e20ed3714
3 changed files with 13 additions and 6 deletions
|
@ -6,8 +6,8 @@
|
||||||
max_clients: 200
|
max_clients: 200
|
||||||
tasks:
|
tasks:
|
||||||
- include: base.yml favcolor=blue
|
- include: base.yml favcolor=blue
|
||||||
- name: write the apache config file using vars set above
|
- name: write the foo config file using vars set above
|
||||||
action: template src=/srv/httpd.j2 dest=/etc/httpd.conf
|
action: template src=foo.j2 dest=/etc/some_random_foo.conf
|
||||||
notify:
|
notify:
|
||||||
- restart apache
|
- restart apache
|
||||||
- name: ensure apache is running
|
- name: ensure apache is running
|
||||||
|
|
|
@ -81,6 +81,7 @@ class PlayBook(object):
|
||||||
# playbook file can be passed in as a path or
|
# playbook file can be passed in as a path or
|
||||||
# as file contents (to support API usage)
|
# as file contents (to support API usage)
|
||||||
|
|
||||||
|
self.basedir = os.path.dirname(playbook)
|
||||||
self.playbook = self._parse_playbook(playbook)
|
self.playbook = self._parse_playbook(playbook)
|
||||||
|
|
||||||
def _include_tasks(self, play, task, dirname, new_tasks):
|
def _include_tasks(self, play, task, dirname, new_tasks):
|
||||||
|
@ -178,7 +179,8 @@ class PlayBook(object):
|
||||||
module_path=self.module_path,
|
module_path=self.module_path,
|
||||||
timeout=self.timeout,
|
timeout=self.timeout,
|
||||||
remote_user=remote_user,
|
remote_user=remote_user,
|
||||||
setup_cache=SETUP_CACHE
|
setup_cache=SETUP_CACHE,
|
||||||
|
basedir=self.basedir
|
||||||
).run()
|
).run()
|
||||||
|
|
||||||
def _run_task(self, pattern=None, task=None, host_list=None,
|
def _run_task(self, pattern=None, task=None, host_list=None,
|
||||||
|
|
|
@ -32,7 +32,8 @@ import Queue
|
||||||
import random
|
import random
|
||||||
import paramiko
|
import paramiko
|
||||||
import jinja2
|
import jinja2
|
||||||
|
from ansible.utils import *
|
||||||
|
|
||||||
################################################
|
################################################
|
||||||
|
|
||||||
def noop(*args, **kwargs):
|
def noop(*args, **kwargs):
|
||||||
|
@ -63,6 +64,7 @@ class Runner(object):
|
||||||
remote_user=C.DEFAULT_REMOTE_USER,
|
remote_user=C.DEFAULT_REMOTE_USER,
|
||||||
remote_pass=C.DEFAULT_REMOTE_PASS,
|
remote_pass=C.DEFAULT_REMOTE_PASS,
|
||||||
background=0,
|
background=0,
|
||||||
|
basedir=None,
|
||||||
setup_cache={},
|
setup_cache={},
|
||||||
verbose=False):
|
verbose=False):
|
||||||
|
|
||||||
|
@ -94,6 +96,9 @@ class Runner(object):
|
||||||
self.remote_pass = remote_pass
|
self.remote_pass = remote_pass
|
||||||
self.background = background
|
self.background = background
|
||||||
|
|
||||||
|
if basedir is None:
|
||||||
|
basedir = os.getcwd()
|
||||||
|
self.basedir = basedir
|
||||||
|
|
||||||
# hosts in each group name in the inventory file
|
# hosts in each group name in the inventory file
|
||||||
self._tmp_paths = {}
|
self._tmp_paths = {}
|
||||||
|
@ -287,7 +292,7 @@ class Runner(object):
|
||||||
# transfer the file to a remote tmp location
|
# transfer the file to a remote tmp location
|
||||||
tmp_path = tmp
|
tmp_path = tmp
|
||||||
tmp_src = tmp_path + source.split('/')[-1]
|
tmp_src = tmp_path + source.split('/')[-1]
|
||||||
self._transfer_file(conn, source, tmp_src)
|
self._transfer_file(conn, path_dwim(self.basedir, source), tmp_src)
|
||||||
|
|
||||||
# install the copy module
|
# install the copy module
|
||||||
self.module_name = 'copy'
|
self.module_name = 'copy'
|
||||||
|
@ -318,7 +323,7 @@ class Runner(object):
|
||||||
tpath = tmp
|
tpath = tmp
|
||||||
tempname = os.path.split(source)[-1]
|
tempname = os.path.split(source)[-1]
|
||||||
temppath = tpath + tempname
|
temppath = tpath + tempname
|
||||||
self._transfer_file(conn, source, temppath)
|
self._transfer_file(conn, path_dwim(self.basedir, source), temppath)
|
||||||
|
|
||||||
# install the template module
|
# install the template module
|
||||||
template_module = self._transfer_module(conn, tmp, 'template')
|
template_module = self._transfer_module(conn, tmp, 'template')
|
||||||
|
|
Loading…
Reference in a new issue