From c9c477d47334dead75f227f6ea1396d1c9400e1a Mon Sep 17 00:00:00 2001 From: Niculut Laurentiu <Laurentiu.Niculut2@hpecds.com> Date: Tue, 14 Dec 2021 09:14:09 +0100 Subject: [PATCH] added output examples --- Databases-templates/mysql-play.tpl | 9 ++------- ansibleBuilder.py | 2 ++ ansibleUtils.py | 11 +++++++++++ parameters.json | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Databases-templates/mysql-play.tpl b/Databases-templates/mysql-play.tpl index fcbfa71..df0de7b 100644 --- a/Databases-templates/mysql-play.tpl +++ b/Databases-templates/mysql-play.tpl @@ -6,14 +6,9 @@ pre_tasks: - name: Install MySQL - apt: name={{ item }} update_cache=yes cache_valid_time=3600 state=present + ###OS###: name={{ item }} update_cache=yes cache_valid_time=3600 state=present with_items: - - mysql-server - - mysql-client - - python-setuptools - - python-mysqldb - - libmysqlclient-dev - - python3-pip +###OS_PACKETS### - name: Remove a symbolic link ansible.builtin.file: diff --git a/ansibleBuilder.py b/ansibleBuilder.py index 880d5ff..424ef70 100644 --- a/ansibleBuilder.py +++ b/ansibleBuilder.py @@ -33,6 +33,8 @@ class AnsibleModule: def edit_template(self, template_type, template_list, template_data, kind): if template_type == "postgres": new_file = ansibleUtils.databases_postgres(template_list, template_data, kind) + if template_type == "mysql": + new_file = ansibleUtils.databases_mysql(template_list, template_data, kind) if template_type == "wordpress": new_file = ansibleUtils.service_wordpress(template_list, template_data, kind) return new_file diff --git a/ansibleUtils.py b/ansibleUtils.py index c43cf11..dbfe787 100644 --- a/ansibleUtils.py +++ b/ansibleUtils.py @@ -20,6 +20,17 @@ def databases_postgres(template_list, template_data, kind): new_template_list = generic_matcher(template_list, specific_data) return "".join(new_template_list) +def databases_mysql(template_list, template_data, kind): + if kind == "vars": + new_template_list = generic_matcher(template_list, template_data[kind]) + if kind == "play": + if template_data[kind]["OS"] == "debian": + specific_data = {"OS": "apt", "OS_PACKETS": " - mysql-server\n - mysql-client\n - python-setuptools\n - python-mysqldb\n - libmysqlclient-dev\n - python3-pip"} + elif template_data[kind]["OS"] == "centos": + specific_data = {"OS": "yum", "OS_PACKETS": " - postgresql10\n - postgresql10-server\n - postgresql10-contrib\n - postgresql10-libs"} + new_template_list = generic_matcher(template_list, specific_data) + return "".join(new_template_list) + def service_wordpress(template_list, template_data, kind): if kind == "vars": new_template_list = generic_matcher(template_list, template_data[kind]) diff --git a/parameters.json b/parameters.json index f7b72cc..cb5f45b 100644 --- a/parameters.json +++ b/parameters.json @@ -44,7 +44,7 @@ "type":"database", "output_path": "Output-code/", "info" : { - "name" : "postgres", + "name" : "mysql", "template_path" : "Databases-templates/" }, "data":{ -- GitLab