mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Playbook dir option (#32275)
* initial add of basedir Allows you to set a 'playbook dir' for adhoc, inventory and console to allow for 'relative path loading'
This commit is contained in:
parent
8037eb7474
commit
95b31a3b61
4 changed files with 13 additions and 2 deletions
|
@ -415,7 +415,7 @@ class CLI(with_metaclass(ABCMeta, object)):
|
|||
@staticmethod
|
||||
def base_parser(usage="", output_opts=False, runas_opts=False, meta_opts=False, runtask_opts=False, vault_opts=False, module_opts=False,
|
||||
async_opts=False, connect_opts=False, subset_opts=False, check_opts=False, inventory_opts=False, epilog=None, fork_opts=False,
|
||||
runas_prompt_opts=False, desc=None):
|
||||
runas_prompt_opts=False, desc=None, basedir_opts=False):
|
||||
''' create an options parser for most ansible scripts '''
|
||||
|
||||
# base opts
|
||||
|
@ -546,6 +546,10 @@ class CLI(with_metaclass(ABCMeta, object)):
|
|||
parser.add_option('--flush-cache', dest='flush_cache', action='store_true',
|
||||
help="clear the fact cache")
|
||||
|
||||
if basedir_opts:
|
||||
parser.add_option('--playbook-dir', default=None, dest='basedir', action='store',
|
||||
help="Since this tool does not use playbooks, use this as a subsitute playbook directory."
|
||||
"This sets the relative path for many features including roles/ group_vars/ etc.")
|
||||
return parser
|
||||
|
||||
@abstractmethod
|
||||
|
@ -775,6 +779,10 @@ class CLI(with_metaclass(ABCMeta, object)):
|
|||
# all needs loader
|
||||
loader = DataLoader()
|
||||
|
||||
basedir = getattr(options, 'basedir', False)
|
||||
if basedir:
|
||||
loader.set_basedir(basedir)
|
||||
|
||||
vault_ids = options.vault_ids
|
||||
default_vault_ids = C.DEFAULT_VAULT_IDENTITY_LIST
|
||||
vault_ids = default_vault_ids + vault_ids
|
||||
|
|
|
@ -60,6 +60,7 @@ class AdHocCLI(CLI):
|
|||
vault_opts=True,
|
||||
fork_opts=True,
|
||||
module_opts=True,
|
||||
basedir_opts=True,
|
||||
desc="Define and run a single task 'playbook' against a set of hosts",
|
||||
epilog="Some modules do not make sense in Ad-Hoc (include, meta, etc)",
|
||||
)
|
||||
|
|
|
@ -88,6 +88,7 @@ class ConsoleCLI(CLI, cmd.Cmd):
|
|||
vault_opts=True,
|
||||
fork_opts=True,
|
||||
module_opts=True,
|
||||
basedir_opts=True,
|
||||
desc="REPL console for executing Ansible tasks.",
|
||||
epilog="This is not a live session/connection, each task executes in the background and returns it's results."
|
||||
)
|
||||
|
|
|
@ -70,7 +70,8 @@ class InventoryCLI(CLI):
|
|||
usage='usage: %prog [options] [host|group]',
|
||||
epilog='Show Ansible inventory information, by default it uses the inventory script JSON format',
|
||||
inventory_opts=True,
|
||||
vault_opts=True
|
||||
vault_opts=True,
|
||||
basedir_opts=True,
|
||||
)
|
||||
|
||||
# Actions
|
||||
|
|
Loading…
Reference in a new issue