Skip to content

Instantly share code, notes, and snippets.

@jlaska
Last active December 31, 2015 19:19
Show Gist options
  • Save jlaska/8032384 to your computer and use it in GitHub Desktop.
Save jlaska/8032384 to your computer and use it in GitHub Desktop.
Prevent ansible-galaxy from init'ing if the desired role contains any ROLE_FILES
diff --git a/bin/ansible-galaxy b/bin/ansible-galaxy
index 7593181..1d99c4c 100755
--- a/bin/ansible-galaxy
+++ b/bin/ansible-galaxy
@@ -445,6 +445,7 @@ def execute_init(args, options):
init_path = get_opt(options, 'init_path', './')
api_server = get_opt(options, "api_server", "galaxy.ansibleworks.com")
force = get_opt(options, 'force', False)
+ ROLE_DIRS = ('defaults','files','handlers','meta','tasks','templates','vars')
api_config = api_get_config(api_server)
if not api_config:
@@ -460,18 +461,18 @@ def execute_init(args, options):
if os.path.isfile(role_path):
print "The path %s already exists, but is a file - aborting" % role_path
sys.exit(1)
- elif not force:
- print "The directory %s already exists."
- print ""
- print "You can use --force to re-initialize this directory,\n" + \
- "however it will reset any main.yml files that may have\n" + \
- "been modified there already."
- sys.exit(1)
+ elif os.path.isdir(role_path) and not force:
+ if any([True for f in os.listdir(role_path) if f in ROLE_DIRS]):
+ print "The directory %s already exists and contains role files." % role_name
+ print ""
+ print "You can use --force to re-initialize this directory,\n" + \
+ "however it will reset any main.yml files that may have\n" + \
+ "been modified there already."
+ sys.exit(1)
except Exception, e:
print "No role name specified for init"
sys.exit(1)
- ROLE_DIRS = ('defaults','files','handlers','meta','tasks','templates','vars')
for dir in ROLE_DIRS:
dir_path = os.path.join(init_path, role_name, dir)
main_yml_path = os.path.join(dir_path, 'main.yml')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment