summaryrefslogtreecommitdiff
path: root/lib/ansible/galaxy
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2018-12-17 18:10:59 -0800
committerToshio Kuratomi <a.badger@gmail.com>2019-01-03 18:12:23 -0800
commitafdbb0d9d5bebb91f632f0d4a1364de5393ba17a (patch)
tree4f688eed3ef5ea1ccd3f80dc716dc62ba7958f3f /lib/ansible/galaxy
parentc18da65089e396ac2e459654398b32f68aecfc98 (diff)
downloadansible-afdbb0d9d5bebb91f632f0d4a1364de5393ba17a.tar.gz
Save the command line arguments into a global context
* Once cli args are parsed, they're constant. So, save the parsed args into the global context for everyone else to use them from now on. * Port cli scripts to use the CLIARGS in the context * Refactor call to parse cli args into the run() method * Fix unittests for changes to the internals of CLI arg parsing * Port callback plugins to use context.CLIARGS * Got rid of the private self._options attribute * Use context.CLIARGS in the individual callback plugins instead. * Also output positional arguments in default and unixy plugins * Code has been simplified since we're now dealing with a dict rather than Optparse.Value
Diffstat (limited to 'lib/ansible/galaxy')
-rw-r--r--lib/ansible/galaxy/__init__.py12
-rw-r--r--lib/ansible/galaxy/api.py7
-rw-r--r--lib/ansible/galaxy/role.py8
3 files changed, 14 insertions, 13 deletions
diff --git a/lib/ansible/galaxy/__init__.py b/lib/ansible/galaxy/__init__.py
index b9048d3db5..76b5363d41 100644
--- a/lib/ansible/galaxy/__init__.py
+++ b/lib/ansible/galaxy/__init__.py
@@ -25,6 +25,7 @@ __metaclass__ = type
import os
+from ansible import context
from ansible.errors import AnsibleError
from ansible.module_utils.six import string_types
@@ -35,19 +36,18 @@ from ansible.module_utils.six import string_types
class Galaxy(object):
''' Keeps global galaxy info '''
- def __init__(self, options):
+ def __init__(self):
- self.options = options
- # self.options.roles_path needs to be a list and will be by default
- roles_path = getattr(self.options, 'roles_path', [])
- # cli option handling is responsible for making roles_path a list
+ # roles_path needs to be a list and will be by default
+ roles_path = context.CLIARGS.get('roles_path', tuple())
+ # cli option handling is responsible for splitting roles_path
self.roles_paths = roles_path
self.roles = {}
# load data path for resource usage
this_dir, this_filename = os.path.split(__file__)
- type_path = getattr(self.options, 'role_type', "default")
+ type_path = context.CLIARGS.get('role_type', "default")
self.DATA_PATH = os.path.join(this_dir, 'data', type_path)
@property
diff --git a/lib/ansible/galaxy/api.py b/lib/ansible/galaxy/api.py
index ead7f26b15..55e46c44f7 100644
--- a/lib/ansible/galaxy/api.py
+++ b/lib/ansible/galaxy/api.py
@@ -24,6 +24,7 @@ __metaclass__ = type
import json
+from ansible import context
import ansible.constants as C
from ansible.errors import AnsibleError
from ansible.galaxy.token import GalaxyToken
@@ -63,7 +64,7 @@ class GalaxyAPI(object):
self.galaxy = galaxy
self.token = GalaxyToken()
self._api_server = C.GALAXY_SERVER
- self._validate_certs = not galaxy.options.ignore_certs
+ self._validate_certs = not context.CLIARGS['ignore_certs']
self.baseurl = None
self.version = None
self.initialized = False
@@ -71,8 +72,8 @@ class GalaxyAPI(object):
display.debug('Validate TLS certificates: %s' % self._validate_certs)
# set the API server
- if galaxy.options.api_server != C.GALAXY_SERVER:
- self._api_server = galaxy.options.api_server
+ if context.CLIARGS['api_server'] != C.GALAXY_SERVER:
+ self._api_server = context.CLIARGS['api_server']
def __auth_header(self):
token = self.token.get()
diff --git a/lib/ansible/galaxy/role.py b/lib/ansible/galaxy/role.py
index cf5cdb9d2e..61776c8850 100644
--- a/lib/ansible/galaxy/role.py
+++ b/lib/ansible/galaxy/role.py
@@ -31,6 +31,7 @@ import yaml
from distutils.version import LooseVersion
from shutil import rmtree
+from ansible import context
from ansible.errors import AnsibleError
from ansible.module_utils._text import to_native, to_text
from ansible.module_utils.urls import open_url
@@ -52,11 +53,10 @@ class GalaxyRole(object):
self._metadata = None
self._install_info = None
- self._validate_certs = not galaxy.options.ignore_certs
+ self._validate_certs = not context.CLIARGS['ignore_certs']
display.debug('Validate TLS certificates: %s' % self._validate_certs)
- self.options = galaxy.options
self.galaxy = galaxy
self.name = name
@@ -196,7 +196,7 @@ class GalaxyRole(object):
if self.scm:
# create tar file from scm url
- tmp_file = RoleRequirement.scm_archive_role(keep_scm_meta=self.options.keep_scm_meta, **self.spec)
+ tmp_file = RoleRequirement.scm_archive_role(keep_scm_meta=context.CLIARGS['keep_scm_meta'], **self.spec)
elif self.src:
if os.path.isfile(self.src):
tmp_file = self.src
@@ -298,7 +298,7 @@ class GalaxyRole(object):
if os.path.exists(self.path):
if not os.path.isdir(self.path):
raise AnsibleError("the specified roles path exists and is not a directory.")
- elif not getattr(self.options, "force", False):
+ elif not context.CLIARGS.get("force", False):
raise AnsibleError("the specified role %s appears to already exist. Use --force to replace it." % self.name)
else:
# using --force, remove the old path