Signed-off-by: Erik Skultety <eskultet(a)redhat.com>
---
guests/lcitool | 50 +++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 45 insertions(+), 5 deletions(-)
diff --git a/guests/lcitool b/guests/lcitool
index 689a8cf..d9b2372 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -175,7 +175,7 @@ class Config:
)
)
- if flavor not in ["test", "jenkins"]:
+ if flavor not in ["test", "jenkins", "gitlab"]:
raise Exception("Invalid flavor '{}'".format(flavor))
return flavor
@@ -185,7 +185,7 @@ class Config:
# The vault password is only needed for the jenkins flavor, but in
# that case we want to make sure there's *something* in there
- if self.get_flavor() != "test":
+ if self.get_flavor() == "jenkins":
vault_pass_file = self._get_config_file("vault-password")
try:
@@ -217,6 +217,38 @@ class Config:
return root_pass_file
+ def get_gitlab_runner_token_file(self):
+ gitlab_runner_token_file =
self._get_config_file("gitlab-runner-token")
+
+ try:
+ with open(gitlab_runner_token_file, "r") as infile:
+ if not infile.readline().strip():
+ raise ValueError
+ except Exception as ex:
+ raise Exception(
+ "Missing or invalid gitlab runner token file ({}): {}".format(
+ gitlab_runner_token_file, ex
+ )
+ )
+
+ return gitlab_runner_token_file
+
+ def get_gitlab_url_file(self):
+ gitlab_url_file = self._get_config_file("gitlab-url")
+
+ try:
+ with open(gitlab_url_file, "r") as infile:
+ if not infile.readline().strip():
+ raise ValueError
+ except Exception as ex:
+ raise Exception(
+ "Missing or invalid gitlab url file ({}): {}".format(
+ gitlab_url_file, ex
+ )
+ )
+
+ return gitlab_url_file
+
class Inventory:
@@ -449,6 +481,8 @@ class Application:
flavor = self._config.get_flavor()
vault_pass_file = self._config.get_vault_password_file()
root_pass_file = self._config.get_root_password_file()
+ gitlab_url_file = self._config.get_gitlab_url_file()
+ gitlab_runner_token_file = self._config.get_gitlab_runner_token_file()
ansible_hosts = ",".join(self._inventory.expand_pattern(hosts))
selected_projects = self._projects.expand_pattern(projects)
@@ -469,7 +503,7 @@ class Application:
playbook_base = os.path.join(base, "playbooks", playbook)
playbook_path = os.path.join(playbook_base, "main.yml")
- extra_vars = json.dumps({
+ extra_vars_d = {
"base": base,
"playbook_base": playbook_base,
"root_password_file": root_pass_file,
@@ -477,7 +511,13 @@ class Application:
"selected_projects": selected_projects,
"git_remote": git_remote,
"git_branch": git_branch,
- })
+ }
+
+ if flavor == "gitlab":
+ extra_vars_d.update([
+ ("gitlab_url_file", gitlab_url_file),
+ ("gitlab_runner_token_file", gitlab_runner_token_file),
+ ])
ansible_playbook = distutils.spawn.find_executable("ansible-playbook")
if ansible_playbook is None:
@@ -486,7 +526,7 @@ class Application:
cmd = [
ansible_playbook,
"--limit", ansible_hosts,
- "--extra-vars", extra_vars,
+ "--extra-vars", json.dumps(extra_vars_d),
]
# Provide the vault password if available
--
2.25.1