diff options
author | Harry Huang <huangxiangyu5@huawei.com> | 2018-02-01 15:56:03 +0800 |
---|---|---|
committer | Harry Huang <huangxiangyu5@huawei.com> | 2018-02-01 19:14:35 +0800 |
commit | 5e02737fa5f23451bbb443bbf9d67cbac603dc46 (patch) | |
tree | b642b808ea19d13b8e7c370bafe4b431e4b7b560 | |
parent | bce23c34f221cdd9a41608c6505b359d99963afe (diff) |
Ansible callback support both V2.3 and V2.4
JIRA: COMPASS-585
1. Add conditional branch to support both ansible
versions
2. Keep callback in ansible_plugins directory which
will contains all plugins upcoming in the future
Change-Id: I11f3d9700e07ad5bd7f03ad56f4e0bc061df05ec
Signed-off-by: Harry Huang <huangxiangyu5@huawei.com>
-rw-r--r-- | deploy/ansible_plugins/callback/playbook_done.py (renamed from deploy/playbook_done.py) | 7 | ||||
-rw-r--r-- | deploy/ansible_plugins/callback/status_callback.py (renamed from deploy/status_callback.py) | 7 | ||||
-rwxr-xr-x | deploy/compass_conf/templates/ansible_installer/openstack_pike/ansible_cfg/HA-ansible-multinodes.tmpl | 2 | ||||
-rwxr-xr-x | util/docker-compose/roles/compass/tasks/main.yml | 15 | ||||
-rwxr-xr-x | util/docker-compose/roles/compass/templates/docker-compose.yml.j2 | 1 |
5 files changed, 19 insertions, 13 deletions
diff --git a/deploy/playbook_done.py b/deploy/ansible_plugins/callback/playbook_done.py index 6b1043d4..4784ff63 100644 --- a/deploy/playbook_done.py +++ b/deploy/ansible_plugins/callback/playbook_done.py @@ -17,6 +17,8 @@ """Ansible playbook callback after a playbook run has completed.""" import sys +from distutils.version import LooseVersion +from ansible import __version__ as __ansible_version__ from ansible.plugins.callback import CallbackBase compass_bin = "/opt/compass/bin" @@ -85,7 +87,10 @@ class CallbackModule(CallbackBase): return def v2_playbook_on_stats(self, stats): - all_vars = self.play.get_variable_manager().get_vars(self.loader) + if LooseVersion(__ansible_version__) < LooseVersion("2.4"): + all_vars = self.play.get_variable_manager().get_vars(self.loader) + else: + all_vars = self.play.get_variable_manager().get_vars() host_vars = all_vars["hostvars"] hosts = sorted(stats.processed.keys()) cluster_name = host_vars[hosts[0]]['cluster_name'] diff --git a/deploy/status_callback.py b/deploy/ansible_plugins/callback/status_callback.py index 6169b87f..b87d2094 100644 --- a/deploy/status_callback.py +++ b/deploy/ansible_plugins/callback/status_callback.py @@ -11,6 +11,8 @@ import httplib import simplejson as json import sys # noqa:F401 +from distutils.version import LooseVersion +from ansible import __version__ as __ansible_version__ from ansible.plugins.callback import CallbackBase COMPASS_HOST = "compass-deck" @@ -101,7 +103,10 @@ class CallbackModule(CallbackBase): def v2_playbook_on_stats(self, stats): self._display.display("playbook_on_stats enter") - all_vars = self.play.get_variable_manager().get_vars(self.loader) + if LooseVersion(__ansible_version__) < LooseVersion("2.4"): + all_vars = self.play.get_variable_manager().get_vars(self.loader) + else: + all_vars = self.play.get_variable_manager().get_vars() host_vars = all_vars["hostvars"] hosts = sorted(stats.processed.keys()) cluster_name = host_vars[hosts[0]]['cluster_name'] diff --git a/deploy/compass_conf/templates/ansible_installer/openstack_pike/ansible_cfg/HA-ansible-multinodes.tmpl b/deploy/compass_conf/templates/ansible_installer/openstack_pike/ansible_cfg/HA-ansible-multinodes.tmpl index cd8c8d30..1d0d6478 100755 --- a/deploy/compass_conf/templates/ansible_installer/openstack_pike/ansible_cfg/HA-ansible-multinodes.tmpl +++ b/deploy/compass_conf/templates/ansible_installer/openstack_pike/ansible_cfg/HA-ansible-multinodes.tmpl @@ -3,7 +3,7 @@ log_path = /var/ansible/run/openstack_pike-$cluster_name/ansible.log host_key_checking = False callback_whitelist = playbook_done, status_callback -callback_plugins = /opt/ansible_callbacks +callback_plugins = /opt/ansible_plugins/callback forks=100 [ssh_connection] diff --git a/util/docker-compose/roles/compass/tasks/main.yml b/util/docker-compose/roles/compass/tasks/main.yml index c7dba96b..46a413b8 100755 --- a/util/docker-compose/roles/compass/tasks/main.yml +++ b/util/docker-compose/roles/compass/tasks/main.yml @@ -95,6 +95,11 @@ "{{ docker_compose_dir }}"/ansible/$i done +- name: copy ansible plugins + copy: + src: "{{ compass_dir }}/deploy/ansible_plugins" + dest: "{{ docker_compose_dir }}" + - name: create run dir file: path: "{{ docker_compose_dir }}/ansible/run" @@ -123,16 +128,6 @@ tags: - redploy -- name: add ansible callback - shell: | - docker cp "{{ item }}" \ - compass-deck:/root/compass-deck/bin/ansible_callbacks - docker cp "{{ item }}" \ - compass-tasks:/opt/ansible_callbacks - with_items: - - "{{ compass_dir }}/deploy/status_callback.py" - - "{{ compass_dir }}/deploy/playbook_done.py" - - name: rm ansible run shell: | docker exec compass-tasks bash -c "rm -rf /var/ansible/run/*" diff --git a/util/docker-compose/roles/compass/templates/docker-compose.yml.j2 b/util/docker-compose/roles/compass/templates/docker-compose.yml.j2 index 7fc8ea3a..f7748634 100755 --- a/util/docker-compose/roles/compass/templates/docker-compose.yml.j2 +++ b/util/docker-compose/roles/compass/templates/docker-compose.yml.j2 @@ -43,6 +43,7 @@ services: volumes: - {{ docker_compose_dir }}/compass_conf:/etc/compass - {{ docker_compose_dir }}/ansible:/var/ansible + - {{ docker_compose_dir }}/ansible_plugins:/opt/ansible_plugins command: - /usr/local/bin/start.sh {% endif %} |