mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-27 23:21:22 -07: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
|
@staticmethod
|
||||||
def base_parser(usage="", output_opts=False, runas_opts=False, meta_opts=False, runtask_opts=False, vault_opts=False, module_opts=False,
|
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,
|
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 '''
|
''' create an options parser for most ansible scripts '''
|
||||||
|
|
||||||
# base opts
|
# base opts
|
||||||
|
@ -546,6 +546,10 @@ class CLI(with_metaclass(ABCMeta, object)):
|
||||||
parser.add_option('--flush-cache', dest='flush_cache', action='store_true',
|
parser.add_option('--flush-cache', dest='flush_cache', action='store_true',
|
||||||
help="clear the fact cache")
|
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
|
return parser
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
@ -775,6 +779,10 @@ class CLI(with_metaclass(ABCMeta, object)):
|
||||||
# all needs loader
|
# all needs loader
|
||||||
loader = DataLoader()
|
loader = DataLoader()
|
||||||
|
|
||||||
|
basedir = getattr(options, 'basedir', False)
|
||||||
|
if basedir:
|
||||||
|
loader.set_basedir(basedir)
|
||||||
|
|
||||||
vault_ids = options.vault_ids
|
vault_ids = options.vault_ids
|
||||||
default_vault_ids = C.DEFAULT_VAULT_IDENTITY_LIST
|
default_vault_ids = C.DEFAULT_VAULT_IDENTITY_LIST
|
||||||
vault_ids = default_vault_ids + vault_ids
|
vault_ids = default_vault_ids + vault_ids
|
||||||
|
|
|
@ -60,6 +60,7 @@ class AdHocCLI(CLI):
|
||||||
vault_opts=True,
|
vault_opts=True,
|
||||||
fork_opts=True,
|
fork_opts=True,
|
||||||
module_opts=True,
|
module_opts=True,
|
||||||
|
basedir_opts=True,
|
||||||
desc="Define and run a single task 'playbook' against a set of hosts",
|
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)",
|
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,
|
vault_opts=True,
|
||||||
fork_opts=True,
|
fork_opts=True,
|
||||||
module_opts=True,
|
module_opts=True,
|
||||||
|
basedir_opts=True,
|
||||||
desc="REPL console for executing Ansible tasks.",
|
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."
|
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]',
|
usage='usage: %prog [options] [host|group]',
|
||||||
epilog='Show Ansible inventory information, by default it uses the inventory script JSON format',
|
epilog='Show Ansible inventory information, by default it uses the inventory script JSON format',
|
||||||
inventory_opts=True,
|
inventory_opts=True,
|
||||||
vault_opts=True
|
vault_opts=True,
|
||||||
|
basedir_opts=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Actions
|
# Actions
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue