Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow .yaml if .yml tasks/handlers/vars are not found in a role #2660

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/ansible/playbook/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ def _load_roles(self, roles, ds):
# <rolename>/handlers/main.yml
# <rolename>/vars/main.yml
# and it auto-extends tasks/handlers/vars_files as appropriate if found
#
# .yaml is also allowed as an extension if .yml files are not
# found first.

if roles is None:
return ds
Expand Down Expand Up @@ -169,15 +172,39 @@ def _load_roles(self, roles, ds):
if with_items:
nt['with_items'] = with_items
new_tasks.append(nt)
else:
task = utils.path_dwim(self.basedir, os.path.join(path, 'tasks', 'main.yaml'))
if os.path.isfile(task):
nt = dict(include=task, vars=has_dict)
if when:
nt['when'] = when
if with_items:
nt['with_items'] = with_items
new_tasks.append(nt)

if os.path.isfile(handler):
nt = dict(include=handler, vars=has_dict)
if when:
nt['when'] = when
if with_items:
nt['with_items'] = with_items
new_handlers.append(nt)
else:
handler = utils.path_dwim(self.basedir, os.path.join(path, 'handlers', 'main.yaml'))
if os.path.isfile(handler):
nt = dict(include=handler, vars=has_dict)
if when:
nt['when'] = when
if with_items:
nt['with_items'] = with_items
new_handlers.append(nt)

if os.path.isfile(vars_file):
new_vars_files.append(vars_file)
else:
vars_file = utils.path_dwim(self.basedir, os.path.join(path, 'vars', 'main.yaml'))
if os.path.isfile(vars_file):
new_vars_files.append(vars_file)

tasks = ds.get('tasks', None)
handlers = ds.get('handlers', None)
Expand Down
11 changes: 11 additions & 0 deletions library/user
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,16 @@ class User(object):

return self.execute_command(cmd)

def get_ssh_public_key(self):
ssh_public_key_file = '%s.pub' % self.get_ssh_key_path()
try:
f = open(ssh_public_key_file)
ssh_public_key = f.read().strip()
f.close()
except IOError:
return None
return ssh_public_key

def create_user(self):
# by default we use the create_user_useradd method
return self.create_user_useradd()
Expand Down Expand Up @@ -1130,6 +1140,7 @@ def main():
else:
result['ssh_fingerprint'] = err.strip()
result['ssh_key_file'] = user.get_ssh_key_path()
result['ssh_public_key'] = user.get_ssh_public_key()


module.exit_json(**result)
Expand Down