Rather than putting all the options to the extra_vars JSON, use the
update method to extend the source dictionary with options coming from
the lcitool config file. By doing this split, we know which options are
hard-coded and which come from external sources. The main reason for this
change though is that some sections/members in the config file are
optional (thus may be missing in the config dictionary) and we'd risk
the KeyError exception if we tried to access them directly when filling
out the extra_vars JSON.
Signed-off-by: Erik Skultety <eskultet(a)redhat.com>
---
guests/lcitool | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/guests/lcitool b/guests/lcitool
index f2b4d44..4cb6e69 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -481,17 +481,22 @@ class Application:
extra_vars_path = os.path.join(tempdir.name, 'extra_vars.json')
with open(extra_vars_path, 'w') as fp:
+
+ # start with generic items not coming from the config
extra_vars = {
"base": base,
"playbook_base": playbook_base,
- "root_password":
self._config.dict["install"]["root_password"],
- "flavor":
self._config.dict["install"]["flavor"],
"selected_projects": selected_projects,
"git_remote": git_remote,
"git_branch": git_branch,
- "gitlab_url":
self._config.dict["gitlab"]["url"],
- "gitlab_runner_secret":
self._config.dict["gitlab"]["token"],
}
+
+ # now add the config vars
+ extra_vars.update(self._config.dict["install"])
+
+ if extra_vars["flavor"] == "gitlab":
+ extra_vars.update(self._config.dict["gitlab"])
+
json.dump(extra_vars, fp)
ansible_playbook = distutils.spawn.find_executable("ansible-playbook")
--
2.25.3