Skip to content
Snippets Groups Projects
Commit 0b600fd2 authored by jurgenhaas's avatar jurgenhaas
Browse files

Manage devop issues in host specific inventories not in company specific ones

parent 8a0adde5
No related branches found
No related tags found
No related merge requests found
...@@ -23,10 +23,18 @@ class GitLabProject(object): ...@@ -23,10 +23,18 @@ class GitLabProject(object):
self._module = module self._module = module
self._gitlab = git self._gitlab = git
def exists(self, group_name, project_name): def exists(self, group_name, project_name, host_name):
if not self.findNamespace(group_name): if not self.findNamespace(group_name):
return False return False
if host_name:
projects = self._gitlab.projects.list(search=host_name)
if len(projects) == 1:
project = projects[0]
self.pid = project.id
self.project = project
return True
project = self._gitlab.projects.get('%s/%s' % (self.namespace, project_name)) project = self._gitlab.projects.get('%s/%s' % (self.namespace, project_name))
if project: if project:
namespace = project.namespace namespace = project.namespace
...@@ -127,6 +135,7 @@ def main(): ...@@ -127,6 +135,7 @@ def main():
login_token=dict(required=False, no_log=True), login_token=dict(required=False, no_log=True),
group=dict(required=False), group=dict(required=False),
name=dict(required=True), name=dict(required=True),
hostname=dict(required=False),
title=dict(required=True), title=dict(required=True),
append_timestamp=dict(required=False, default=False, type='bool'), append_timestamp=dict(required=False, default=False, type='bool'),
description=dict(required=False), description=dict(required=False),
...@@ -150,6 +159,7 @@ def main(): ...@@ -150,6 +159,7 @@ def main():
login_token = module.params['login_token'] login_token = module.params['login_token']
group_name = module.params['group'] group_name = module.params['group']
project_name = module.params['name'] project_name = module.params['name']
host_name = module.params['hostname']
title = module.params['title'] title = module.params['title']
append_timestamp = module.params['append_timestamp'] append_timestamp = module.params['append_timestamp']
description = module.params['description'] description = module.params['description']
...@@ -173,6 +183,8 @@ def main(): ...@@ -173,6 +183,8 @@ def main():
project_name = project_name.lower() project_name = project_name.lower()
if group_name is not None: if group_name is not None:
group_name = group_name.lower() group_name = group_name.lower()
if host_name is not None:
host_name = host_name.lower()
# Lets make an connection to the Gitlab server_url, with either login_user and login_password # Lets make an connection to the Gitlab server_url, with either login_user and login_password
# or with login_token # or with login_token
...@@ -188,7 +200,7 @@ def main(): ...@@ -188,7 +200,7 @@ def main():
# Validate if project exists and get its ID # Validate if project exists and get its ID
metaProject = GitLabProject(module, git) # type: GitLabProject metaProject = GitLabProject(module, git) # type: GitLabProject
project_exists = metaProject.exists(group_name, project_name) project_exists = metaProject.exists(group_name, project_name, host_name)
if not project_exists: if not project_exists:
module.fail_json(msg="Gitlab project does not exist") module.fail_json(msg="Gitlab project does not exist")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment