Fixes #5341 Use constants.py to set the roles directory
This commit is contained in:
parent
982c9394b2
commit
5d022182fe
2 changed files with 7 additions and 5 deletions
|
@ -37,6 +37,8 @@ from distutils.version import LooseVersion
|
||||||
from jinja2 import Environment
|
from jinja2 import Environment
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
import ansible.constants as C
|
||||||
|
|
||||||
default_meta_template = """---
|
default_meta_template = """---
|
||||||
galaxy_info:
|
galaxy_info:
|
||||||
author: {{ author }}
|
author: {{ author }}
|
||||||
|
@ -137,7 +139,7 @@ def build_option_parser(action):
|
||||||
# options that apply to more than one action
|
# options that apply to more than one action
|
||||||
if action != "init":
|
if action != "init":
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
'-p', '--roles-path', dest='roles_path', default="/etc/ansible/roles",
|
'-p', '--roles-path', dest='roles_path', default=C.DEFAULT_ROLES_PATH,
|
||||||
help='The path to the directory containing your roles.'
|
help='The path to the directory containing your roles.'
|
||||||
'The default is the roles_path configured in your '
|
'The default is the roles_path configured in your '
|
||||||
'ansible.cfg file (/etc/ansible/roles if not configured)')
|
'ansible.cfg file (/etc/ansible/roles if not configured)')
|
||||||
|
@ -272,7 +274,7 @@ def get_role_path(role_name, options):
|
||||||
Returns the role path based on the roles_path option
|
Returns the role path based on the roles_path option
|
||||||
and the role name.
|
and the role name.
|
||||||
"""
|
"""
|
||||||
roles_path = get_opt(options,'roles_path','/etc/ansible/roles')
|
roles_path = get_opt(options,'roles_path')
|
||||||
return os.path.join(roles_path, role_name)
|
return os.path.join(roles_path, role_name)
|
||||||
|
|
||||||
def get_role_metadata(role_name, options):
|
def get_role_metadata(role_name, options):
|
||||||
|
@ -280,8 +282,8 @@ def get_role_metadata(role_name, options):
|
||||||
Returns the metadata as YAML, if the file 'meta/main.yml'
|
Returns the metadata as YAML, if the file 'meta/main.yml'
|
||||||
exists in the specified role_path
|
exists in the specified role_path
|
||||||
"""
|
"""
|
||||||
|
role_path = os.path.join(get_role_path(role_name, options), 'meta/main.yml')
|
||||||
try:
|
try:
|
||||||
role_path = os.path.join(get_role_path(role_name, options), 'meta/main.yml')
|
|
||||||
if os.path.isfile(role_path):
|
if os.path.isfile(role_path):
|
||||||
f = open(role_path, 'r')
|
f = open(role_path, 'r')
|
||||||
meta_data = yaml.safe_load(f)
|
meta_data = yaml.safe_load(f)
|
||||||
|
@ -689,7 +691,7 @@ def execute_list(args, options):
|
||||||
print "The role %s was not found" % role_name
|
print "The role %s was not found" % role_name
|
||||||
else:
|
else:
|
||||||
# show all valid roles in the roles_path directory
|
# show all valid roles in the roles_path directory
|
||||||
roles_path = get_opt(options, 'roles_path', '/etc/ansible/roles')
|
roles_path = get_opt(options, 'roles_path')
|
||||||
if not os.path.exists(roles_path):
|
if not os.path.exists(roles_path):
|
||||||
print "The path %s does not exist. Please specify a valid path with --roles-path" % roles_path
|
print "The path %s does not exist. Please specify a valid path with --roles-path" % roles_path
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -100,7 +100,7 @@ DEFAULTS='defaults'
|
||||||
# configurable things
|
# configurable things
|
||||||
DEFAULT_HOST_LIST = shell_expand_path(get_config(p, DEFAULTS, 'hostfile', 'ANSIBLE_HOSTS', '/etc/ansible/hosts'))
|
DEFAULT_HOST_LIST = shell_expand_path(get_config(p, DEFAULTS, 'hostfile', 'ANSIBLE_HOSTS', '/etc/ansible/hosts'))
|
||||||
DEFAULT_MODULE_PATH = get_config(p, DEFAULTS, 'library', 'ANSIBLE_LIBRARY', DIST_MODULE_PATH)
|
DEFAULT_MODULE_PATH = get_config(p, DEFAULTS, 'library', 'ANSIBLE_LIBRARY', DIST_MODULE_PATH)
|
||||||
DEFAULT_ROLES_PATH = get_config(p, DEFAULTS, 'roles_path', 'ANSIBLE_ROLES_PATH', None)
|
DEFAULT_ROLES_PATH = get_config(p, DEFAULTS, 'roles_path', 'ANSIBLE_ROLES_PATH', '/etc/ansible/roles')
|
||||||
DEFAULT_REMOTE_TMP = shell_expand_path(get_config(p, DEFAULTS, 'remote_tmp', 'ANSIBLE_REMOTE_TEMP', '$HOME/.ansible/tmp'))
|
DEFAULT_REMOTE_TMP = shell_expand_path(get_config(p, DEFAULTS, 'remote_tmp', 'ANSIBLE_REMOTE_TEMP', '$HOME/.ansible/tmp'))
|
||||||
DEFAULT_MODULE_NAME = get_config(p, DEFAULTS, 'module_name', None, 'command')
|
DEFAULT_MODULE_NAME = get_config(p, DEFAULTS, 'module_name', None, 'command')
|
||||||
DEFAULT_PATTERN = get_config(p, DEFAULTS, 'pattern', None, '*')
|
DEFAULT_PATTERN = get_config(p, DEFAULTS, 'pattern', None, '*')
|
||||||
|
|
Loading…
Reference in a new issue