From 3a0c895920657eb905ca3e1dcf3a11c8268f3810 Mon Sep 17 00:00:00 2001 From: Xicheng Chang Date: Wed, 22 Apr 2015 18:16:24 -0700 Subject: [PATCH] Use template to generate ansible.cfg instead of writing files 1. add removing ansible run env in refresh.sh 2. update ansible_installer.py for generate ansible.cfg Change-Id: I5da9cec07f063a4879262f7a726270439031ec1d --- bin/refresh.sh | 1 + .../ansible_installer/ansible_installer.py | 36 ++++++++++--------- conf/package_installer/ansible-juno.conf | 1 - .../openstack_juno/ansible_cfg/allinone.tmpl | 5 +++ .../ansible_cfg/multinodes.tmpl | 5 +++ .../ansible_cfg/single-controller.tmpl | 5 +++ 6 files changed, 36 insertions(+), 17 deletions(-) create mode 100644 conf/templates/ansible_installer/openstack_juno/ansible_cfg/allinone.tmpl create mode 100644 conf/templates/ansible_installer/openstack_juno/ansible_cfg/multinodes.tmpl create mode 100644 conf/templates/ansible_installer/openstack_juno/ansible_cfg/single-controller.tmpl diff --git a/bin/refresh.sh b/bin/refresh.sh index 41d95cde..fd553b43 100755 --- a/bin/refresh.sh +++ b/bin/refresh.sh @@ -4,6 +4,7 @@ service mysqld restart /opt/compass/bin/manage_db.py createdb /opt/compass/bin/clean_installers.py --noasync /opt/compass/bin/clean_installation_logs.py +rm -rf /var/ansible/run/* service httpd restart service rsyslog restart service redis restart diff --git a/compass/deployment/installers/pk_installers/ansible_installer/ansible_installer.py b/compass/deployment/installers/pk_installers/ansible_installer/ansible_installer.py index 4e91f21a..1b4fc9d3 100644 --- a/compass/deployment/installers/pk_installers/ansible_installer/ansible_installer.py +++ b/compass/deployment/installers/pk_installers/ansible_installer/ansible_installer.py @@ -200,6 +200,19 @@ class AnsibleInstaller(PKInstaller): return self.get_config_from_template(hosts_tmpl_path, global_vars_dict) + def _generate_ansible_cfg_attributes(self, global_vars_dict): + ansible_cfg_tmpl_path = os.path.join( + os.path.join(self.tmpl_dir, 'ansible_cfg'), self.tmpl_name + ) + if not os.path.exists(ansible_cfg_tmpl_path): + logging.error("cfg template '%s' does not exist", self.tmpl_name) + raise Exception("Template '%s' does not exist!" % self.tmpl_name) + + return self.get_config_from_template( + ansible_cfg_tmpl_path, + global_vars_dict + ) + def get_config_from_template(self, tmpl_path, vars_dict): logging.debug("vars_dict is %s", vars_dict) @@ -224,22 +237,6 @@ class AnsibleInstaller(PKInstaller): ansible_run_destination = os.path.join(self.ansible_run_dir, env_name) os.mkdir(ansible_run_destination) - ansible_log_path = os.path.join( - ansible_run_destination, - self.log_file - ) - log_option = "log_path = %s" % ansible_log_path - host_key_checking = "host_key_checking = False" - ansible_cfg_file = os.path.join( - ansible_run_destination, - self.ansible_config - ) - with open(ansible_cfg_file, 'w') as cfg: - cfg.write('[defaults]\n') - cfg.write(log_option) - cfg.write('\n') - cfg.write(host_key_checking) - # copy roles to run env dirs = self.runner_dirs files = self.runner_files @@ -275,6 +272,12 @@ class AnsibleInstaller(PKInstaller): ansible_run_destination, self.hosts_path ) + cfg_config = self._generate_ansible_cfg_attributes(global_vars_dict) + cfg_destination = os.path.join( + ansible_run_destination, + self.ansible_config + ) + os.mkdir(inventory_dir) os.mkdir(vars_dir) @@ -283,6 +286,7 @@ class AnsibleInstaller(PKInstaller): self.serialize_config(inv_config, inventory_destination) self.serialize_config(vars_config, group_vars_destination) self.serialize_config(hosts_config, hosts_destination) + self.serialize_config(cfg_config, cfg_destination) def deploy(self): """Start to deploy a distributed system. Return both cluster and hosts diff --git a/conf/package_installer/ansible-juno.conf b/conf/package_installer/ansible-juno.conf index 835d5b91..7f9ca184 100644 --- a/conf/package_installer/ansible-juno.conf +++ b/conf/package_installer/ansible-juno.conf @@ -3,7 +3,6 @@ INSTANCE_NAME = 'ansible_installer' SETTINGS = { 'ansible_dir': '/var/ansible', 'ansible_run_dir': '/var/ansible/run', - 'ansible_log_file': 'ansible.log', 'ansible_config': 'ansible.cfg', 'playbook_file': 'site.yml', 'inventory_file': 'inventory.yml', diff --git a/conf/templates/ansible_installer/openstack_juno/ansible_cfg/allinone.tmpl b/conf/templates/ansible_installer/openstack_juno/ansible_cfg/allinone.tmpl new file mode 100644 index 00000000..6221dbe5 --- /dev/null +++ b/conf/templates/ansible_installer/openstack_juno/ansible_cfg/allinone.tmpl @@ -0,0 +1,5 @@ +#set cluster_name = $getVar('name', '') +[defaults] +log_path = /var/ansible/run/openstack_juno-$cluster_name/ansible.log +host_key_checking = False +callback_plugins = /opt/compass/bin/ansible_callbacks diff --git a/conf/templates/ansible_installer/openstack_juno/ansible_cfg/multinodes.tmpl b/conf/templates/ansible_installer/openstack_juno/ansible_cfg/multinodes.tmpl new file mode 100644 index 00000000..6221dbe5 --- /dev/null +++ b/conf/templates/ansible_installer/openstack_juno/ansible_cfg/multinodes.tmpl @@ -0,0 +1,5 @@ +#set cluster_name = $getVar('name', '') +[defaults] +log_path = /var/ansible/run/openstack_juno-$cluster_name/ansible.log +host_key_checking = False +callback_plugins = /opt/compass/bin/ansible_callbacks diff --git a/conf/templates/ansible_installer/openstack_juno/ansible_cfg/single-controller.tmpl b/conf/templates/ansible_installer/openstack_juno/ansible_cfg/single-controller.tmpl new file mode 100644 index 00000000..6221dbe5 --- /dev/null +++ b/conf/templates/ansible_installer/openstack_juno/ansible_cfg/single-controller.tmpl @@ -0,0 +1,5 @@ +#set cluster_name = $getVar('name', '') +[defaults] +log_path = /var/ansible/run/openstack_juno-$cluster_name/ansible.log +host_key_checking = False +callback_plugins = /opt/compass/bin/ansible_callbacks